Skip to content

Commit 293ae0b

Browse files
committed
[clang][Interp] Actually consider ConstantExpr result
Since we have visitAPValue now, we might as well use it here. Differential Revision: https://reviews.llvm.org/D158502
1 parent c990d94 commit 293ae0b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,14 @@ bool ByteCodeExprGen<Emitter>::VisitSubstNonTypeTemplateParmExpr(
634634

635635
template <class Emitter>
636636
bool ByteCodeExprGen<Emitter>::VisitConstantExpr(const ConstantExpr *E) {
637-
// TODO: Check if the ConstantExpr already has a value set and if so,
638-
// use that instead of evaluating it again.
637+
// Try to emit the APValue directly, without visiting the subexpr.
638+
// This will only fail if we can't emit the APValue, so won't emit any
639+
// diagnostics or any double values.
640+
std::optional<PrimType> T = classify(E->getType());
641+
if (T && E->hasAPValueResult() &&
642+
this->visitAPValue(E->getAPValueResult(), *T, E))
643+
return true;
644+
639645
return this->delegate(E->getSubExpr());
640646
}
641647

0 commit comments

Comments
 (0)