[clang] [clang][bytecode] Check value-dependency before calling evaluateValue() (PR #196931)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 11 04:58:09 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
As always.
---
Full diff: https://github.com/llvm/llvm-project/pull/196931.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3-2)
- (modified) clang/test/AST/ByteCode/c.c (+9)
``````````diff
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}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/196931
More information about the cfe-commits
mailing list