[clang] [clang][bytecode] Handle a null record better (PR #179645)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 03:53:07 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This would otherwise later assert in vsitZeroRecordInitializer().
---
Full diff: https://github.com/llvm/llvm-project/pull/179645.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2)
- (modified) clang/test/AST/ByteCode/invalid.cpp (+8)
``````````diff
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();
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/179645
More information about the cfe-commits
mailing list