[clang] [clang][bytecode] Create descriptor for invalid record fields (PR #187311)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 18 09:38:55 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We otherwise refuse to register the Record for the RecordDecl entirely.
---
Full diff: https://github.com/llvm/llvm-project/pull/187311.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Program.cpp (+1-1)
- (modified) clang/test/AST/ByteCode/lambda.cpp (+16-1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index efef5db177e56..ccef38ab14ebe 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -384,7 +384,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
(Desc->isPrimitiveArray() && Desc->getPrimType() == PT_Ptr) ||
(Desc->ElemRecord && Desc->ElemRecord->hasPtrField());
} else {
- return nullptr;
+ Desc = allocateDescriptor(FD);
}
Fields.emplace_back(FD, Desc, BaseSize);
BaseSize += align(Desc->getAllocSize());
diff --git a/clang/test/AST/ByteCode/lambda.cpp b/clang/test/AST/ByteCode/lambda.cpp
index e4390483d0053..efc006dbfb1bc 100644
--- a/clang/test/AST/ByteCode/lambda.cpp
+++ b/clang/test/AST/ByteCode/lambda.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both -std=c++20 %s
-// RUN: %clang_cc1 -verify=ref,both -std=c++20 %s
+// RUN: %clang_cc1 -verify=ref,both -std=c++20 %s
constexpr int a = 12;
constexpr int f = [c = a]() { return c; }();
@@ -278,6 +278,21 @@ namespace InvalidCapture {
both-note {{read of non-const variable 'n' is not allowed in a constant expression}}
} ();
}
+
+ class Foo {
+ void a; // both-error {{field has incomplete type 'void'}}
+
+ public:
+ constexpr int bar() {
+ auto *p = &a;
+ *p;
+
+ auto b = [this]() {return 42;};
+ return b();
+ }
+ };
+ Foo FF;
+ static_assert(FF.bar() == 42, "");
}
constexpr int fn() {
``````````
</details>
https://github.com/llvm/llvm-project/pull/187311
More information about the cfe-commits
mailing list