[clang] bcbad84 - [clang][bytecode] Only revisit C variables with valid initializers (#194881)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 20:50:53 PDT 2026


Author: Timm Baeder
Date: 2026-04-30T05:50:49+02:00
New Revision: bcbad84a7c56c99c0d628e2b24fac856c87bb98a

URL: https://github.com/llvm/llvm-project/commit/bcbad84a7c56c99c0d628e2b24fac856c87bb98a
DIFF: https://github.com/llvm/llvm-project/commit/bcbad84a7c56c99c0d628e2b24fac856c87bb98a.diff

LOG: [clang][bytecode] Only revisit C variables with valid initializers (#194881)

We don't mark them as constexpr-unknown, so check that the initializer
can be evaluated.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/c.c
    clang/test/Parser/pragma-fenv_access.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index d4bbb8d3a8a3e..349bbed6830ba 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7624,8 +7624,8 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
 
   // For C.
   if (!Ctx.getLangOpts().CPlusPlus) {
-    if (VD->getAnyInitializer() && DeclType.isConstant(Ctx.getASTContext()) &&
-        !VD->isWeak())
+    if (VD->getInit() && DeclType.isConstant(Ctx.getASTContext()) &&
+        !VD->isWeak() && VD->evaluateValue())
       return revisit(VD, /*IsConstexprUnknown=*/false);
     return this->emitDummyPtr(D, E);
   }

diff  --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index b1009c0fdf71e..851f28ea77739 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -235,8 +235,7 @@ int castViaInt[*(int*)(unsigned long)"test"]; // ref-error {{variable length arr
                                               // expected-error {{variable length array}} \
                                               // pedantic-expected-error {{variable length array}}
 
-const void (*const funcp)(void) = (void*)123; // pedantic-warning {{converts between void pointer and function pointer}} \
-                                              // pedantic-expected-note {{this conversion is not allowed in a constant expression}}
+const void (*const funcp)(void) = (void*)123; // pedantic-warning {{converts between void pointer and function pointer}}
 _Static_assert(funcp == (void*)0, ""); // all-error {{failed due to requirement 'funcp == (void *)0'}} \
                                        // pedantic-warning {{expression is not an integer constant expression}}
 _Static_assert(funcp == (void*)123, ""); // pedantic-warning {{equality comparison between function pointer and void pointer}} \

diff  --git a/clang/test/Parser/pragma-fenv_access.c b/clang/test/Parser/pragma-fenv_access.c
index 76256cff1b49b..024f7a2128754 100644
--- a/clang/test/Parser/pragma-fenv_access.c
+++ b/clang/test/Parser/pragma-fenv_access.c
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -ffp-exception-behavior=strict -DSTRICT -fsyntax-only -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -DCPP -DSTRICT -ffp-exception-behavior=strict -fsyntax-only -verify %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffp-exception-behavior=strict -DSTRICT -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x c++ -DCPP -DSTRICT -ffp-exception-behavior=strict -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
 #ifdef CPP
 #define CONST constexpr
 #else


        


More information about the cfe-commits mailing list