File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -2459,6 +2459,17 @@ bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
24592459 return this ->emitGetPtrThisField (Offset, E);
24602460 }
24612461
2462+ // Lazily visit global declarations we haven't seen yet.
2463+ // This happens in C.
2464+ if (!Ctx.getLangOpts ().CPlusPlus ) {
2465+ if (const auto *VD = dyn_cast<VarDecl>(D);
2466+ VD && VD->hasGlobalStorage () && VD->getAnyInitializer ()) {
2467+ if (!this ->visitVarDecl (VD))
2468+ return false ;
2469+ // Retry.
2470+ return this ->VisitDeclRefExpr (E);
2471+ }
2472+ }
24622473 return false ;
24632474}
24642475
Original file line number Diff line number Diff line change 11// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
2+ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -pedantic -verify=pedantic-expected %s
23// RUN: %clang_cc1 -verify=ref %s
4+ // RUN: %clang_cc1 -pedantic -verify=pedantic-ref %s
35
46/// expected-no-diagnostics
5- /// ref-no-diagnostics
67
78_Static_assert (1 , "" );
89_Static_assert (0 != 1 , "" );
9- _Static_assert (1.0 == 1.0 , "" );
10+ _Static_assert (1.0 == 1.0 , "" ); // pedantic-ref-warning {{not an integer constant expression}} \
11+ // pedantic-expected-warning {{not an integer constant expression}}
1012_Static_assert ( (5 > 4 ) + (3 > 2 ) == 2 , "" );
1113
14+ /// FIXME: Should also be rejected in the new interpreter
1215int a = (1 == 1 ? 5 : 3 );
16+ _Static_assert (a == 5 , "" ); // ref-error {{not an integral constant expression}} \
17+ // pedantic-ref-error {{not an integral constant expression}} \
18+ // pedantic-expected-warning {{not an integer constant expression}}
19+
20+ const int b = 3 ;
21+ _Static_assert (b == 3 , "" ); // pedantic-ref-warning {{not an integer constant expression}} \
22+ // pedantic-expected-warning {{not an integer constant expression}}
23+
You can’t perform that action at this time.
0 commit comments