1 //===-- Value.cpp -----------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines support functions for the `Value` type.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Analysis/FlowSensitive/Value.h"
14 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
15 #include "llvm/Support/Casting.h"
20 static bool areEquivalentIndirectionValues(const Value
&Val1
,
22 if (auto *IndVal1
= dyn_cast
<ReferenceValue
>(&Val1
)) {
23 auto *IndVal2
= cast
<ReferenceValue
>(&Val2
);
24 return &IndVal1
->getReferentLoc() == &IndVal2
->getReferentLoc();
26 if (auto *IndVal1
= dyn_cast
<PointerValue
>(&Val1
)) {
27 auto *IndVal2
= cast
<PointerValue
>(&Val2
);
28 return &IndVal1
->getPointeeLoc() == &IndVal2
->getPointeeLoc();
33 bool areEquivalentValues(const Value
&Val1
, const Value
&Val2
) {
34 return &Val1
== &Val2
|| (Val1
.getKind() == Val2
.getKind() &&
35 (isa
<TopBoolValue
>(&Val1
) ||
36 areEquivalentIndirectionValues(Val1
, Val2
)));
39 raw_ostream
&operator<<(raw_ostream
&OS
, const Value
&Val
) {
40 switch (Val
.getKind()) {
41 case Value::Kind::Reference
: {
42 const auto *RV
= cast
<ReferenceValue
>(&Val
);
43 return OS
<< "Reference(" << &RV
->getReferentLoc() << ")";
45 case Value::Kind::Pointer
: {
46 const auto *PV
= dyn_cast
<PointerValue
>(&Val
);
47 return OS
<< "Pointer(" << &PV
->getPointeeLoc() << ")";
49 // FIXME: support remaining cases.
51 return OS
<< debugString(Val
.getKind());
55 } // namespace dataflow