Author: Timm Baeder
Date: 2026-03-23T06:51:27+01:00
New Revision: 054e11d1a17e5ba88bb1a8ef32fad3346e80b186

URL: 
https://github.com/llvm/llvm-project/commit/054e11d1a17e5ba88bb1a8ef32fad3346e80b186
DIFF: 
https://github.com/llvm/llvm-project/commit/054e11d1a17e5ba88bb1a8ef32fad3346e80b186.diff

LOG: [clang][bytecode] Create descriptor for invalid record fields (#187311)

We otherwise refuse to register the Record for the RecordDecl entirely.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Program.cpp
    clang/test/AST/ByteCode/lambda.cpp

Removed: 
    


################################################################################
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..2ab8f4b0b0be0 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, ""); // both-error {{not an integral constant 
expression}}
 }
 
 constexpr int fn() {


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

Reply via email to