Coverage Report

Created: 2023-05-31 04:38

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Analysis/FlowSensitive/Value.cpp
Line
Count
Source (jump to first uncovered line)
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
13
#include "clang/Analysis/FlowSensitive/Value.h"
14
#include "clang/Analysis/FlowSensitive/DebugSupport.h"
15
#include "llvm/Support/Casting.h"
16
17
namespace clang {
18
namespace dataflow {
19
20
static bool areEquivalentIndirectionValues(const Value &Val1,
21
624
                                           const Value &Val2) {
22
624
  if (auto *IndVal1 = dyn_cast<ReferenceValue>(&Val1)) {
23
4
    auto *IndVal2 = cast<ReferenceValue>(&Val2);
24
4
    return &IndVal1->getReferentLoc() == &IndVal2->getReferentLoc();
25
4
  }
26
620
  if (auto *IndVal1 = dyn_cast<PointerValue>(&Val1)) {
27
106
    auto *IndVal2 = cast<PointerValue>(&Val2);
28
106
    return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();
29
106
  }
30
514
  return false;
31
620
}
32
33
5.16k
bool areEquivalentValues(const Value &Val1, const Value &Val2) {
34
5.16k
  return &Val1 == &Val2 || 
(675
Val1.getKind() == Val2.getKind()675
&&
35
675
                            
(635
isa<TopBoolValue>(&Val1)635
||
36
635
                             
areEquivalentIndirectionValues(Val1, Val2)624
));
37
5.16k
}
38
39
53
raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {
40
53
  switch (Val.getKind()) {
41
0
  case Value::Kind::Reference: {
42
0
    const auto *RV = cast<ReferenceValue>(&Val);
43
0
    return OS << "Reference(" << &RV->getReferentLoc() << ")";
44
0
  }
45
0
  case Value::Kind::Pointer: {
46
0
    const auto *PV = dyn_cast<PointerValue>(&Val);
47
0
    return OS << "Pointer(" << &PV->getPointeeLoc() << ")";
48
0
  }
49
  // FIXME: support remaining cases.
50
53
  default:
51
53
    return OS << debugString(Val.getKind());
52
53
  }
53
53
}
54
55
} // namespace dataflow
56
} // namespace clang