clang 22.0.0git
Value.cpp
Go to the documentation of this file.
1//===-- Value.cpp -----------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines support functions for the `Value` type.
10//
11//===----------------------------------------------------------------------===//
12
14
15namespace clang {
16namespace dataflow {
17
18static bool areEquivalentIndirectionValues(const Value &Val1,
19 const Value &Val2) {
20 if (auto *IndVal1 = dyn_cast<PointerValue>(&Val1)) {
21 auto *IndVal2 = cast<PointerValue>(&Val2);
22 return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
23 }
24 return false;
25}
26
27bool areEquivalentValues(const Value &Val1, const Value &Val2) {
28 if (&Val1 == &Val2)
29 return true;
30 if (Val1.getKind() != Val2.getKind())
31 return false;
32 // If values are distinct and have properties, we don't consider them equal,
33 // leaving equality up to the user model.
34 if (!Val1.properties().empty() || !Val2.properties().empty())
35 return false;
36 if (isa<TopBoolValue>(&Val1))
37 return true;
38 return areEquivalentIndirectionValues(Val1, Val2);
39}
40
41raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {
42 switch (Val.getKind()) {
44 return OS << "Integer(@" << &Val << ")";
46 return OS << "Pointer(" << &cast<PointerValue>(Val).getPointeeLoc() << ")";
48 return OS << "TopBool(" << cast<TopBoolValue>(Val).getAtom() << ")";
50 return OS << "AtomicBool(" << cast<AtomicBoolValue>(Val).getAtom() << ")";
52 return OS << "FormulaBool(" << cast<FormulaBoolValue>(Val).formula() << ")";
53 }
54 llvm_unreachable("Unknown clang::dataflow::Value::Kind enum");
55}
56
57} // namespace dataflow
58} // namespace clang
Base class for all values computed by abstract interpretation.
Definition Value.h:33
Kind getKind() const
Definition Value.h:55
llvm::iterator_range< llvm::StringMap< Value * >::const_iterator > properties() const
Definition Value.h:73
Dataflow Directional Tag Classes.
Definition AdornedCFG.h:29
bool areEquivalentValues(const Value &Val1, const Value &Val2)
An equivalence relation for values.
Definition Value.cpp:27
static bool areEquivalentIndirectionValues(const Value &Val1, const Value &Val2)
Definition Value.cpp:18
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, Atom A)
Definition Formula.h:126
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
U cast(CodeGen::Address addr)
Definition Address.h:327