clang 17.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<ReferenceValue>(&Val1)) {
23 auto *IndVal2 = cast<ReferenceValue>(&Val2);
24 return &IndVal1->getReferentLoc() == &IndVal2->getReferentLoc();
25 }
26 if (auto *IndVal1 = dyn_cast<PointerValue>(&Val1)) {
27 auto *IndVal2 = cast<PointerValue>(&Val2);
28 return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
29 }
30 return false;
31}
32
33bool areEquivalentValues(const Value &Val1, const Value &Val2) {
34 return &Val1 == &Val2 || (Val1.getKind() == Val2.getKind() &&
35 (isa<TopBoolValue>(&Val1) ||
37}
38
39raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {
40 switch (Val.getKind()) {
42 const auto *RV = cast<ReferenceValue>(&Val);
43 return OS << "Reference(" << &RV->getReferentLoc() << ")";
44 }
46 const auto *PV = dyn_cast<PointerValue>(&Val);
47 return OS << "Pointer(" << &PV->getPointeeLoc() << ")";
48 }
49 // FIXME: support remaining cases.
50 default:
51 return OS << debugString(Val.getKind());
52 }
53}
54
55} // namespace dataflow
56} // namespace clang
llvm::raw_ostream & OS
Definition: Logger.cpp:24
Base class for all values computed by abstract interpretation.
Definition: Value.h:33
Kind getKind() const
Definition: Value.h:61
llvm::StringRef debugString(Value::Kind Kind)
Returns a string representation of a value kind.
bool areEquivalentValues(const Value &Val1, const Value &Val2)
An equivalence relation for values.
Definition: Value.cpp:33
static bool areEquivalentIndirectionValues(const Value &Val1, const Value &Val2)
Definition: Value.cpp:20
std::ostream & operator<<(std::ostream &Os, const clang::dataflow::MapLattice< Key, ElementLattice > &M)
Definition: MapLattice.h:116