brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 1f7d029 Raw
59 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9//  This file defines support functions for the `Value` type.10//11//===----------------------------------------------------------------------===//12 13#include "clang/Analysis/FlowSensitive/Value.h"14 15namespace clang {16namespace dataflow {17 18static bool areEquivalentIndirectionValues(const Value &Val1,19                                           const Value &Val2) {20  if (auto *IndVal1 = dyn_cast<PointerValue>(&Val1)) {21    auto *IndVal2 = cast<PointerValue>(&Val2);22    return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();23  }24  return false;25}26 27bool areEquivalentValues(const Value &Val1, const Value &Val2) {28  if (&Val1 == &Val2)29    return true;30  if (Val1.getKind() != Val2.getKind())31    return false;32  // If values are distinct and have properties, we don't consider them equal,33  // leaving equality up to the user model.34  if (!Val1.properties().empty() || !Val2.properties().empty())35    return false;36  if (isa<TopBoolValue>(&Val1))37    return true;38  return areEquivalentIndirectionValues(Val1, Val2);39}40 41raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {42  switch (Val.getKind()) {43  case Value::Kind::Integer:44    return OS << "Integer(@" << &Val << ")";45  case Value::Kind::Pointer:46    return OS << "Pointer(" << &cast<PointerValue>(Val).getPointeeLoc() << ")";47  case Value::Kind::TopBool:48    return OS << "TopBool(" << cast<TopBoolValue>(Val).getAtom() << ")";49  case Value::Kind::AtomicBool:50    return OS << "AtomicBool(" << cast<AtomicBoolValue>(Val).getAtom() << ")";51  case Value::Kind::FormulaBool:52    return OS << "FormulaBool(" << cast<FormulaBoolValue>(Val).formula() << ")";53  }54  llvm_unreachable("Unknown clang::dataflow::Value::Kind enum");55}56 57} // namespace dataflow58} // namespace clang59