Path: blob/main/contrib/llvm-project/clang/lib/Analysis/FlowSensitive/Value.cpp
35266 views
//===-- Value.cpp -----------------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines support functions for the `Value` type.9//10//===----------------------------------------------------------------------===//1112#include "clang/Analysis/FlowSensitive/Value.h"13#include "clang/Analysis/FlowSensitive/DebugSupport.h"14#include "llvm/Support/Casting.h"1516namespace clang {17namespace dataflow {1819static bool areEquivalentIndirectionValues(const Value &Val1,20const Value &Val2) {21if (auto *IndVal1 = dyn_cast<PointerValue>(&Val1)) {22auto *IndVal2 = cast<PointerValue>(&Val2);23return &IndVal1->getPointeeLoc() == &IndVal2->getPointeeLoc();24}25return false;26}2728bool areEquivalentValues(const Value &Val1, const Value &Val2) {29if (&Val1 == &Val2)30return true;31if (Val1.getKind() != Val2.getKind())32return false;33// If values are distinct and have properties, we don't consider them equal,34// leaving equality up to the user model.35if (!Val1.properties().empty() || !Val2.properties().empty())36return false;37if (isa<TopBoolValue>(&Val1))38return true;39return areEquivalentIndirectionValues(Val1, Val2);40}4142raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {43switch (Val.getKind()) {44case Value::Kind::Integer:45return OS << "Integer(@" << &Val << ")";46case Value::Kind::Pointer:47return OS << "Pointer(" << &cast<PointerValue>(Val).getPointeeLoc() << ")";48case Value::Kind::TopBool:49return OS << "TopBool(" << cast<TopBoolValue>(Val).getAtom() << ")";50case Value::Kind::AtomicBool:51return OS << "AtomicBool(" << cast<AtomicBoolValue>(Val).getAtom() << ")";52case Value::Kind::FormulaBool:53return OS << "FormulaBool(" << cast<FormulaBoolValue>(Val).formula() << ")";54}55llvm_unreachable("Unknown clang::dataflow::Value::Kind enum");56}5758} // namespace dataflow59} // namespace clang606162