clang 19.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
15#include "llvm/Support/Casting.h"
16
17namespace clang {
18namespace dataflow {
19
20static bool areEquivalentIndirectionValues(const Value &Val1,
21 const Value &Val2) {
22 if (auto *IndVal1 = dyn_cast<PointerValue>(&Val1)) {
23 auto *IndVal2 = cast<PointerValue>(&Val2);
24 return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
25 }
26 return false;
27}
28
29bool areEquivalentValues(const Value &Val1, const Value &Val2) {
30 if (&Val1 == &Val2)
31 return true;
32 if (Val1.getKind() != Val2.getKind())
33 return false;
34 // If values are distinct and have properties, we don't consider them equal,
35 // leaving equality up to the user model.
36 if (!Val1.properties().empty() || !Val2.properties().empty())
37 return false;
38 if (isa<TopBoolValue>(&Val1))
39 return true;
40 return areEquivalentIndirectionValues(Val1, Val2);
41}
42
43raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {
44 switch (Val.getKind()) {
46 return OS << "Integer(@" << &Val << ")";
48 return OS << "Pointer(" << &cast<PointerValue>(Val).getPointeeLoc() << ")";
50 return OS << "TopBool(" << cast<TopBoolValue>(Val).getAtom() << ")";
52 return OS << "AtomicBool(" << cast<AtomicBoolValue>(Val).getAtom() << ")";
54 return OS << "FormulaBool(" << cast<FormulaBoolValue>(Val).formula() << ")";
55 }
56 llvm_unreachable("Unknown clang::dataflow::Value::Kind enum");
57}
58
59} // namespace dataflow
60} // 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
bool areEquivalentValues(const Value &Val1, const Value &Val2)
An equivalence relation for values.
Definition: Value.cpp:29
static bool areEquivalentIndirectionValues(const Value &Val1, const Value &Val2)
Definition: Value.cpp:20
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, Atom A)
Definition: Formula.h:125
The JSON file list parser is used to communicate input to InstallAPI.