[clang] [clang][bytecode] Only revisit C variables with valid initializers (PR #194881)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 08:15:21 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/194881
We don't mark them as constexpr-unknown, so check that the initializer can be evaluated.
>From 003a94ffa6b60a8436b66a0cc17cb43808836d85 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 29 Apr 2026 17:13:06 +0200
Subject: [PATCH] [clang][bytecode] Only revisit C variables with valid
initializers
We don't mark them as constexpr-unknown, so check that the initializer
can be evaluated.
---
clang/lib/AST/ByteCode/Compiler.cpp | 4 ++--
clang/test/AST/ByteCode/c.c | 3 +--
clang/test/Parser/pragma-fenv_access.c | 4 ++++
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 98d092554e129..e2407f28eb700 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7639,8 +7639,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