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
<PointerValue
>(&Val1
)) {
23 auto *IndVal2
= cast
<PointerValue
>(&Val2
);
24 return &IndVal1
->getPointeeLoc() == &IndVal2
->getPointeeLoc();
29 bool areEquivalentValues(const Value
&Val1
, const Value
&Val2
) {
30 return &Val1
== &Val2
|| (Val1
.getKind() == Val2
.getKind() &&
31 (isa
<TopBoolValue
>(&Val1
) ||
32 areEquivalentIndirectionValues(Val1
, Val2
)));
35 raw_ostream
&operator<<(raw_ostream
&OS
, const Value
&Val
) {
36 switch (Val
.getKind()) {
37 case Value::Kind::Pointer
: {
38 const auto *PV
= dyn_cast
<PointerValue
>(&Val
);
39 return OS
<< "Pointer(" << &PV
->getPointeeLoc() << ")";
41 // FIXME: support remaining cases.
43 return OS
<< debugString(Val
.getKind());
47 } // namespace dataflow