Author: Timm Baeder
Date: 2026-02-04T14:17:11+01:00
New Revision: 890cdbe65358eb137788ea5d3a8007ec238be26b

URL: 
https://github.com/llvm/llvm-project/commit/890cdbe65358eb137788ea5d3a8007ec238be26b
DIFF: 
https://github.com/llvm/llvm-project/commit/890cdbe65358eb137788ea5d3a8007ec238be26b.diff

LOG: [clang][bytecode] Handle a null record better (#179645)

This would otherwise later assert in vsitZeroRecordInitializer().

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/invalid.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7401eccb4dbdd..db6d562836feb 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4504,6 +4504,8 @@ bool 
Compiler<Emitter>::visitZeroArrayInitializer(QualType T, const Expr *E) {
   }
   if (ElemType->isRecordType()) {
     const Record *R = getRecord(ElemType);
+    if (!R)
+      return false;
 
     for (size_t I = 0; I != NumElems; ++I) {
       if (!this->emitConstUint32(I, E))

diff  --git a/clang/test/AST/ByteCode/invalid.cpp 
b/clang/test/AST/ByteCode/invalid.cpp
index 5f287c77e5418..c8298fa2c2b9b 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -143,3 +143,11 @@ namespace BitCastWithErrors {
   template<class T> int f(); // both-note {{candidate template ignored}}
   static union { char *x = f(); }; // both-error {{no matching function for 
call to 'f'}}
 }
+
+namespace NullRecord {
+  struct S1; // both-note {{forward declaration}}
+  struct S2 {
+    S1 s[2]; // both-error {{field has incomplete type 'S1'}}
+  };
+  S2 s = S2();
+}


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

Reply via email to