https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/179645

This would otherwise later assert in vsitZeroRecordInitializer().

>From cc427487cdd85d1684a51983fce5f3a93f27fd88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Wed, 4 Feb 2026 12:51:27 +0100
Subject: [PATCH] [clang][bytecode] Handle a null record better

This would otherwise later assert in vsitZeroRecordInitializer().
---
 clang/lib/AST/ByteCode/Compiler.cpp | 2 ++
 clang/test/AST/ByteCode/invalid.cpp | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index af076f90733df..13bd853b022a3 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4501,6 +4501,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