[clang] [clang][bytecode] Always check for initialization in RetValue (PR #233189)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 17 22:31:04 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Since we always call `toRValue()` here, all the fields we read need to be initialized.
Fixes https://github.com/llvm/llvm-project/issues/232904
---
Full diff: https://github.com/llvm/llvm-project/pull/233189.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+1-1)
- (modified) clang/test/AST/ByteCode/cxx2a.cpp (+15)
``````````diff
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 72ed8ad1f7a836..bfc01a3b0e9776 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -331,7 +331,7 @@ bool EvalEmitter::emitRetValue(SourceInfo Info) {
if (!EvalResult.checkDynamicAllocations(S, Ptr, Info))
return false;
- if (CheckFullyInitialized && !EvalResult.checkFullyInitialized(S, Ptr))
+ if (!EvalResult.checkFullyInitialized(S, Ptr))
return false;
if (!EvalResult.checkLValueFields(S, Ptr, Info, ConstexprKind))
return false;
diff --git a/clang/test/AST/ByteCode/cxx2a.cpp b/clang/test/AST/ByteCode/cxx2a.cpp
index 9fc434708b8bf2..92b82389ee81ee 100644
--- a/clang/test/AST/ByteCode/cxx2a.cpp
+++ b/clang/test/AST/ByteCode/cxx2a.cpp
@@ -331,3 +331,18 @@ namespace UnionNoActivate {
}
static_assert(g()); // both-error {{constant expression}} both-note {{in call}}
}
+
+namespace UninitializedMemberFromConsteval {
+ struct A {
+ int x; // both-note {{subobject declared here}}
+ consteval A() { x = 4; }
+ consteval A(const A &) {}
+ };
+ void f() {
+ auto b = [] { // both-error {{call to immediate function}} \
+ // both-note {{subobject 'x' is not initialized}}
+ auto z = [a = A()] {};
+ return z;
+ }();
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/233189
More information about the cfe-commits
mailing list