[clang] [clang][bytecode] Don't check global variable init size (PR #212092)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 25 23:07:00 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/212092
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.
>From 12c5f241df67106333c2a787331a1199e59d47bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 26 Jul 2026 08:03:46 +0200
Subject: [PATCH] [clang][bytecode] Don't check global variable init size
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.
---
clang/lib/AST/ByteCode/Compiler.cpp | 8 +++++---
clang/lib/AST/ByteCode/Compiler.h | 2 +-
clang/test/AST/ByteCode/constexpr-steps.cpp | 14 ++++++++++++++
3 files changed, 20 insertions(+), 4 deletions(-)
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
+ };
More information about the cfe-commits
mailing list