https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/196931

As always.

>From 81e9108f56a08a1729255e8b4a9ccc88a1347e78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 11 May 2026 13:56:17 +0200
Subject: [PATCH] [clang][bytecode] Check value-dependency before calling
 evaluateValue()

As always.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 5 +++--
 clang/test/AST/ByteCode/c.c         | 9 +++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index bcdbd68731ee5..20051c5250cd1 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7683,8 +7683,9 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, 
const Expr *E) {
 
   // For C.
   if (!Ctx.getLangOpts().CPlusPlus) {
-    if (VD->getInit() && DeclType.isConstant(Ctx.getASTContext()) &&
-        !VD->isWeak() && VD->evaluateValue())
+    if (VD->getInit() && !VD->getInit()->isValueDependent() &&
+        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 851f28ea77739..e82336e9731ba 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -457,3 +457,12 @@ void labelAndNull(void) { int bar = &*(void *)0 - &&baz; } 
// all-error {{use of
 
 void nonNumberRem(void) { *((int *)0) = (long)foo % 42; } // all-warning 
{{indirection of non-volatile null pointer will be deleted, not trap}} \
                                                           // all-note 
{{consider using __builtin_trap() or qualifying pointer with 'volatile'}}
+
+struct Oops {
+  int a; // all-note {{previous declaration is here}}
+  double a; // all-error {{duplicate member 'a'}}
+};
+void evaluatevalue(void) {
+  const struct Oops s = {0, 0.};
+  *(int *)(&s.a) = 42; // all-warning {{cast from 'const int *' to 'int *' 
drops const qualifier}}
+}

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

Reply via email to