Skip to content

Commit ad49fe3

Browse files
committed
[clang][Interp] Don't return success for already failed global variables
We might be visiting them more than once. We used to return true for second and subsequent cases, just because we had already visited it before.
1 parent 1197fca commit ad49fe3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,12 @@ template <class Emitter>
25102510
bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
25112511
assert(!VD->isInvalidDecl() && "Trying to constant evaluate an invalid decl");
25122512

2513+
// Global variable we've already seen but that's uninitialized means
2514+
// evaluating the initializer failed. Just return failure.
2515+
if (std::optional<unsigned> Index = P.getGlobal(VD);
2516+
Index && !P.getPtrGlobal(*Index).isInitialized())
2517+
return false;
2518+
25132519
// Create and initialize the variable.
25142520
if (!this->visitVarDecl(VD))
25152521
return false;

clang/test/SemaCXX/PR20334-std_initializer_list_diagnosis_assertion.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm-only %s
22
// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s -DCPP98
3+
// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm-only %s -fexperimental-new-constant-interpreter
4+
// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s -DCPP98 -fexperimental-new-constant-interpreter
5+
36

47
namespace std {
58
template <class _E>

0 commit comments

Comments
 (0)