From dbb95c2a851c64e50ca9801a331cb871da88be49 Mon Sep 17 00:00:00 2001 From: Wei Yi Tee Date: Tue, 16 Aug 2022 12:34:42 +0000 Subject: [PATCH] [clang][dataflow] Debug string for value kinds. Differential Revision: https://reviews.llvm.org/D131891 --- .../Analysis/FlowSensitive/DebugSupport.h | 8 +++-- .../Analysis/FlowSensitive/DebugSupport.cpp | 31 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h index b8efdeb61d28..ca50ffc5f5c8 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h +++ b/clang/include/clang/Analysis/FlowSensitive/DebugSupport.h @@ -20,15 +20,19 @@ #include "clang/Analysis/FlowSensitive/Solver.h" #include "clang/Analysis/FlowSensitive/Value.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringRef.h" namespace clang { namespace dataflow { +/// Returns a string representation of a value kind. +llvm::StringRef debugString(Value::Kind Kind); + /// Returns a string representation of a boolean assignment to true or false. -std::string debugString(Solver::Result::Assignment Assignment); +llvm::StringRef debugString(Solver::Result::Assignment Assignment); /// Returns a string representation of the result status of a SAT check. -std::string debugString(Solver::Result::Status Status); +llvm::StringRef debugString(Solver::Result::Status Status); /// Returns a string representation for the boolean value `B`. /// diff --git a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp index 714ad08643ed..220617ab9e30 100644 --- a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp +++ b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp @@ -18,6 +18,7 @@ #include "clang/Analysis/FlowSensitive/Value.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormatAdapters.h" @@ -31,7 +32,33 @@ using llvm::AlignStyle; using llvm::fmt_pad; using llvm::formatv; -std::string debugString(Solver::Result::Assignment Assignment) { +llvm::StringRef debugString(Value::Kind Kind) { + switch (Kind) { + case Value::Kind::Integer: + return "Integer"; + case Value::Kind::Reference: + return "Reference"; + case Value::Kind::Pointer: + return "Pointer"; + case Value::Kind::Struct: + return "Struct"; + case Value::Kind::AtomicBool: + return "AtomicBool"; + case Value::Kind::Conjunction: + return "Conjunction"; + case Value::Kind::Disjunction: + return "Disjunction"; + case Value::Kind::Negation: + return "Negation"; + case Value::Kind::Implication: + return "Implication"; + case Value::Kind::Biconditional: + return "Biconditional"; + } + llvm_unreachable("Unhandled value kind"); +} + +llvm::StringRef debugString(Solver::Result::Assignment Assignment) { switch (Assignment) { case Solver::Result::Assignment::AssignedFalse: return "False"; @@ -41,7 +68,7 @@ std::string debugString(Solver::Result::Assignment Assignment) { llvm_unreachable("Booleans can only be assigned true/false"); } -std::string debugString(Solver::Result::Status Status) { +llvm::StringRef debugString(Solver::Result::Status Status) { switch (Status) { case Solver::Result::Status::Satisfiable: return "Satisfiable";