[clang] [clang][bytecode] Create descriptor for invalid record fields (PR #187311)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 18 08:57:55 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/187311
We otherwise refuse to register the Record for the RecordDecl entirely.
>From 14f50422303de98dd022502664b0944544fe413f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 18 Mar 2026 16:55:27 +0100
Subject: [PATCH] [clang][bytecode] Create descriptor for invalid record fields
---
clang/lib/AST/ByteCode/Program.cpp | 2 +-
clang/test/AST/ByteCode/lambda.cpp | 17 ++++++++++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
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() {
More information about the cfe-commits
mailing list