tbaeder updated this revision to Diff 546882.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156794/new/

https://reviews.llvm.org/D156794

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/c.c


Index: clang/test/AST/Interp/c.c
===================================================================
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -1,12 +1,23 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -pedantic 
-verify=pedantic-expected %s
 // RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -pedantic -verify=pedantic-ref %s
 
 /// expected-no-diagnostics
-/// ref-no-diagnostics
 
 _Static_assert(1, "");
 _Static_assert(0 != 1, "");
-_Static_assert(1.0 == 1.0, "");
+_Static_assert(1.0 == 1.0, ""); // pedantic-ref-warning {{not an integer 
constant expression}} \
+                                // pedantic-expected-warning {{not an integer 
constant expression}}
 _Static_assert( (5 > 4) + (3 > 2) == 2, "");
 
+/// FIXME: Should also be rejected in the new interpreter
 int a = (1 == 1 ? 5 : 3);
+_Static_assert(a == 5, ""); // ref-error {{not an integral constant 
expression}} \
+                            // pedantic-ref-error {{not an integral constant 
expression}} \
+                            // pedantic-expected-warning {{not an integer 
constant expression}}
+
+const int b = 3;
+_Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant 
expression}} \
+                            // pedantic-expected-warning {{not an integer 
constant expression}}
+
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2169,6 +2169,17 @@
     return this->emitGetPtrThisField(Offset, E);
   }
 
+  // Lazily visit global declarations we haven't seen yet.
+  // This happens in C.
+  if (!Ctx.getLangOpts().CPlusPlus) {
+    if (const auto *VD = dyn_cast<VarDecl>(D);
+        VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) {
+      if (!this->visitVarDecl(VD))
+        return false;
+      // Retry.
+      return this->VisitDeclRefExpr(E);
+    }
+  }
   return false;
 }
 


Index: clang/test/AST/Interp/c.c
===================================================================
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -1,12 +1,23 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -pedantic -verify=pedantic-expected %s
 // RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -pedantic -verify=pedantic-ref %s
 
 /// expected-no-diagnostics
-/// ref-no-diagnostics
 
 _Static_assert(1, "");
 _Static_assert(0 != 1, "");
-_Static_assert(1.0 == 1.0, "");
+_Static_assert(1.0 == 1.0, ""); // pedantic-ref-warning {{not an integer constant expression}} \
+                                // pedantic-expected-warning {{not an integer constant expression}}
 _Static_assert( (5 > 4) + (3 > 2) == 2, "");
 
+/// FIXME: Should also be rejected in the new interpreter
 int a = (1 == 1 ? 5 : 3);
+_Static_assert(a == 5, ""); // ref-error {{not an integral constant expression}} \
+                            // pedantic-ref-error {{not an integral constant expression}} \
+                            // pedantic-expected-warning {{not an integer constant expression}}
+
+const int b = 3;
+_Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \
+                            // pedantic-expected-warning {{not an integer constant expression}}
+
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2169,6 +2169,17 @@
     return this->emitGetPtrThisField(Offset, E);
   }
 
+  // Lazily visit global declarations we haven't seen yet.
+  // This happens in C.
+  if (!Ctx.getLangOpts().CPlusPlus) {
+    if (const auto *VD = dyn_cast<VarDecl>(D);
+        VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) {
+      if (!this->visitVarDecl(VD))
+        return false;
+      // Retry.
+      return this->VisitDeclRefExpr(E);
+    }
+  }
   return false;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to