Skip to content

Commit c22a2fd

Browse files
authored
[clang][bytecode][NFC] Clean up EvaluationResult (#155782)
Remove incorrect comments, unused includes, an unused function and make the Ctx member debug-build-only.
1 parent baf9d2c commit c22a2fd

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

clang/lib/AST/ByteCode/Disasm.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ LLVM_DUMP_METHOD void Block::dump(llvm::raw_ostream &OS) const {
549549
}
550550

551551
LLVM_DUMP_METHOD void EvaluationResult::dump() const {
552-
assert(Ctx);
553552
auto &OS = llvm::errs();
554553

555554
if (empty()) {
@@ -558,6 +557,9 @@ LLVM_DUMP_METHOD void EvaluationResult::dump() const {
558557
OS << "Invalid\n";
559558
} else {
560559
OS << "Value: ";
560+
#ifndef NDEBUG
561+
assert(Ctx);
561562
Value.dump(OS, Ctx->getASTContext());
563+
#endif
562564
}
563565
}

clang/lib/AST/ByteCode/EvaluationResult.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "clang/AST/APValue.h"
1313
#include "clang/AST/Decl.h"
1414
#include "clang/AST/Expr.h"
15-
#include <optional>
16-
#include <variant>
1715

1816
namespace clang {
1917
namespace interp {
@@ -25,8 +23,8 @@ class InterpState;
2523

2624
/// Defines the result of an evaluation.
2725
///
28-
/// The result might be in different forms--one of the pointer types,
29-
/// an APValue, or nothing.
26+
/// The Kind defined if the evaluation was invalid, valid (but empty, e.g. for
27+
/// void expressions) or if we have a valid evaluation result.
3028
///
3129
/// We use this class to inspect and diagnose the result, as well as
3230
/// convert it to the requested form.
@@ -41,16 +39,12 @@ class EvaluationResult final {
4139
using DeclTy = llvm::PointerUnion<const Decl *, const Expr *>;
4240

4341
private:
42+
#ifndef NDEBUG
4443
const Context *Ctx = nullptr;
44+
#endif
4545
APValue Value;
4646
ResultKind Kind = Empty;
47-
DeclTy Source = nullptr; // Currently only needed for dump().
48-
49-
EvaluationResult(ResultKind Kind) : Kind(Kind) {
50-
// Leave everything empty. Can be used as an
51-
// error marker or for void return values.
52-
assert(Kind == Valid || Kind == Invalid);
53-
}
47+
DeclTy Source = nullptr;
5448

5549
void setSource(DeclTy D) { Source = D; }
5650

@@ -69,7 +63,11 @@ class EvaluationResult final {
6963
}
7064

7165
public:
66+
#ifndef NDEBUG
7267
EvaluationResult(const Context *Ctx) : Ctx(Ctx) {}
68+
#else
69+
EvaluationResult(const Context *Ctx) {}
70+
#endif
7371

7472
bool empty() const { return Kind == Empty; }
7573
bool isInvalid() const { return Kind == Invalid; }
@@ -94,7 +92,7 @@ class EvaluationResult final {
9492
if (const auto *D =
9593
dyn_cast_if_present<ValueDecl>(Source.dyn_cast<const Decl *>()))
9694
return D->getType();
97-
else if (const auto *E = Source.dyn_cast<const Expr *>())
95+
if (const auto *E = Source.dyn_cast<const Expr *>())
9896
return E->getType();
9997
return QualType();
10098
}

0 commit comments

Comments
 (0)