Skip to content

Commit 4d7f4a7

Browse files
committed
[clang][Interp] Only lazily visit constant globals
Differential Revision: https://reviews.llvm.org/D158516
1 parent 5c4d35d commit 4d7f4a7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,8 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
25362536
// This happens in C.
25372537
if (!Ctx.getLangOpts().CPlusPlus) {
25382538
if (const auto *VD = dyn_cast<VarDecl>(D);
2539-
VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) {
2539+
VD && VD->hasGlobalStorage() && VD->getAnyInitializer() &&
2540+
VD->getType().isConstQualified()) {
25402541
if (!this->visitVarDecl(VD))
25412542
return false;
25422543
// Retry.

clang/test/AST/Interp/c.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ _Static_assert(!!1.0, ""); // pedantic-ref-warning {{not an integer constant exp
1414
// pedantic-expected-warning {{not an integer constant expression}}
1515
_Static_assert(!!1, "");
1616

17-
/// FIXME: Should also be rejected in the new interpreter
18-
int a = (1 == 1 ? 5 : 3);
17+
int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \
18+
// pedantic-expected-note {{declared here}}
1919
_Static_assert(a == 5, ""); // ref-error {{not an integral constant expression}} \
2020
// pedantic-ref-error {{not an integral constant expression}} \
21-
// pedantic-expected-warning {{not an integer constant expression}}
21+
// expected-error {{not an integral constant expression}} \
22+
// expected-note {{read of non-const variable}} \
23+
// pedantic-expected-error {{not an integral constant expression}} \
24+
// pedantic-expected-note {{read of non-const variable}}
25+
2226

2327
const int b = 3;
2428
_Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \

0 commit comments

Comments
 (0)