[clang] c22a2fd - [clang][bytecode][NFC] Clean up EvaluationResult (#155782)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 28 01:53:43 PDT 2025
Author: Timm Baeder
Date: 2025-08-28T10:53:40+02:00
New Revision: c22a2fdf4d96b6e07dfe22ff956899201da95c05
URL: https://github.com/llvm/llvm-project/commit/c22a2fdf4d96b6e07dfe22ff956899201da95c05
DIFF: https://github.com/llvm/llvm-project/commit/c22a2fdf4d96b6e07dfe22ff956899201da95c05.diff
LOG: [clang][bytecode][NFC] Clean up EvaluationResult (#155782)
Remove incorrect comments, unused includes, an unused function and make
the Ctx member debug-build-only.
Added:
Modified:
clang/lib/AST/ByteCode/Disasm.cpp
clang/lib/AST/ByteCode/EvaluationResult.h
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp
index 6ca6e93c46177..ac904d359d8cc 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -549,7 +549,6 @@ LLVM_DUMP_METHOD void Block::dump(llvm::raw_ostream &OS) const {
}
LLVM_DUMP_METHOD void EvaluationResult::dump() const {
- assert(Ctx);
auto &OS = llvm::errs();
if (empty()) {
@@ -558,6 +557,9 @@ LLVM_DUMP_METHOD void EvaluationResult::dump() const {
OS << "Invalid\n";
} else {
OS << "Value: ";
+#ifndef NDEBUG
+ assert(Ctx);
Value.dump(OS, Ctx->getASTContext());
+#endif
}
}
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.h b/clang/lib/AST/ByteCode/EvaluationResult.h
index d00b9ca02a48d..c296cc98ca375 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.h
+++ b/clang/lib/AST/ByteCode/EvaluationResult.h
@@ -12,8 +12,6 @@
#include "clang/AST/APValue.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
-#include <optional>
-#include <variant>
namespace clang {
namespace interp {
@@ -25,8 +23,8 @@ class InterpState;
/// Defines the result of an evaluation.
///
-/// The result might be in
diff erent forms--one of the pointer types,
-/// an APValue, or nothing.
+/// The Kind defined if the evaluation was invalid, valid (but empty, e.g. for
+/// void expressions) or if we have a valid evaluation result.
///
/// We use this class to inspect and diagnose the result, as well as
/// convert it to the requested form.
@@ -41,16 +39,12 @@ class EvaluationResult final {
using DeclTy = llvm::PointerUnion<const Decl *, const Expr *>;
private:
+#ifndef NDEBUG
const Context *Ctx = nullptr;
+#endif
APValue Value;
ResultKind Kind = Empty;
- DeclTy Source = nullptr; // Currently only needed for dump().
-
- EvaluationResult(ResultKind Kind) : Kind(Kind) {
- // Leave everything empty. Can be used as an
- // error marker or for void return values.
- assert(Kind == Valid || Kind == Invalid);
- }
+ DeclTy Source = nullptr;
void setSource(DeclTy D) { Source = D; }
@@ -69,7 +63,11 @@ class EvaluationResult final {
}
public:
+#ifndef NDEBUG
EvaluationResult(const Context *Ctx) : Ctx(Ctx) {}
+#else
+ EvaluationResult(const Context *Ctx) {}
+#endif
bool empty() const { return Kind == Empty; }
bool isInvalid() const { return Kind == Invalid; }
@@ -94,7 +92,7 @@ class EvaluationResult final {
if (const auto *D =
dyn_cast_if_present<ValueDecl>(Source.dyn_cast<const Decl *>()))
return D->getType();
- else if (const auto *E = Source.dyn_cast<const Expr *>())
+ if (const auto *E = Source.dyn_cast<const Expr *>())
return E->getType();
return QualType();
}
More information about the cfe-commits
mailing list