llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

The current interpreter doesn't do this either. If we do, the clang build fails 
because AMDGPUGenGlobalISel.inc: contains a global constexpr array called 
MatchTable0 with 1'926'005 elements.

---
Full diff: https://github.com/llvm/llvm-project/pull/212092.diff


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+5-3) 
- (modified) clang/lib/AST/ByteCode/Compiler.h (+1-1) 
- (modified) clang/test/AST/ByteCode/constexpr-steps.cpp (+14) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 35667a9132680..99f34219da5a6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -287,7 +287,7 @@ template <class Emitter> class InitStackScope final {
 /// Scope used to handle temporaries in toplevel variable declarations.
 template <class Emitter> class DeclScope final : public LocalScope<Emitter> {
 public:
-  DeclScope(Compiler<Emitter> *Ctx, const ValueDecl *VD)
+  DeclScope(Compiler<Emitter> *Ctx, const VarDecl *VD)
       : LocalScope<Emitter>(Ctx), Scope(Ctx->P),
         OldInitializingDecl(Ctx->InitializingDecl) {
     Ctx->InitializingDecl = VD;
@@ -301,7 +301,7 @@ template <class Emitter> class DeclScope final : public 
LocalScope<Emitter> {
 
 private:
   Program::DeclScope Scope;
-  const ValueDecl *OldInitializingDecl;
+  const VarDecl *OldInitializingDecl;
 };
 
 /// Scope used to handle initialization methods.
@@ -2442,7 +2442,9 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr 
*> Inits,
         Ctx.getASTContext().getAsConstantArrayType(QT);
     uint64_t NumElems = CAT->getZExtSize();
 
-    if (Initializing && !this->emitCheckArrayDestSize(NumElems, E))
+    if (Initializing &&
+        (!InitializingDecl || InitializingDecl->hasLocalStorage()) &&
+        !this->emitCheckArrayDestSize(NumElems, E))
       return false;
 
     if (Inits.size() == 1 && QT == Inits[0]->getType())
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 9eb8069496099..ebeffdd804d82 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -494,7 +494,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, 
bool>,
   /// Flag inidicating if we're initializing an already created
   /// variable. This is set in visitInitializer().
   bool Initializing = false;
-  const ValueDecl *InitializingDecl = nullptr;
+  const VarDecl *InitializingDecl = nullptr;
 
   llvm::SmallVector<InitLink> InitStack;
   bool InitStackActive = false;
diff --git a/clang/test/AST/ByteCode/constexpr-steps.cpp 
b/clang/test/AST/ByteCode/constexpr-steps.cpp
index bd461547032a9..593a146a6d9f9 100644
--- a/clang/test/AST/ByteCode/constexpr-steps.cpp
+++ b/clang/test/AST/ByteCode/constexpr-steps.cpp
@@ -15,3 +15,17 @@ constexpr void addr() { // expected-error {{never produces a 
constant expression
 static_assert((addr(), 1) == 1); // expected-error {{not an integral constant 
expression}} \
                                  // expected-note {{in call to}}
 
+/// No error here, even if the array has > 100 elements, an even if they are 
not coming from an array filler.
+
+constexpr int f[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0
+                    };

``````````

</details>


https://github.com/llvm/llvm-project/pull/212092
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to