[clang] f4aaf6f - [clang][bytecode] Fix a crash in codegen (#151515)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 31 06:50:05 PDT 2025
Author: Timm Baeder
Date: 2025-07-31T15:50:02+02:00
New Revision: f4aaf6fe5c6b7911d8b5f669646372c8c7dc19f4
URL: https://github.com/llvm/llvm-project/commit/f4aaf6fe5c6b7911d8b5f669646372c8c7dc19f4
DIFF: https://github.com/llvm/llvm-project/commit/f4aaf6fe5c6b7911d8b5f669646372c8c7dc19f4.diff
LOG: [clang][bytecode] Fix a crash in codegen (#151515)
getRecord() can return nullptr if any one of the fields does, in this
case because the array is too large for us to allocate.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/codegen.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 8bde5875ce55a..8b9e5e0cb318e 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1758,6 +1758,9 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
return this->delegate(Inits[0]);
+ if (!R)
+ return false;
+
auto initPrimitiveField = [=](const Record::Field *FieldToInit,
const Expr *Init, PrimType T,
bool Activate = false) -> bool {
diff --git a/clang/test/AST/ByteCode/codegen.cpp b/clang/test/AST/ByteCode/codegen.cpp
index 6f9e75eac6026..1bc756c515ac8 100644
--- a/clang/test/AST/ByteCode/codegen.cpp
+++ b/clang/test/AST/ByteCode/codegen.cpp
@@ -23,6 +23,10 @@ S s;
// CHECK: @sp = constant ptr getelementptr (i8, ptr @s, i64 16), align 8
float &sp = s.c[3];
+namespace NearlyZeroInit {
+ // CHECK: @_ZN14NearlyZeroInit1bE ={{.*}} global{{.*}} { i32, <{ i32, [2147483647 x i32] }> } { i32 1, <{ i32, [2147483647 x i32] }> <{ i32 2, [2147483647 x i32] zeroinitializer }> }{{.*}}
+ struct B { int n; int arr[1024 * 1024 * 1024 * 2u]; } b = {1, {2}};
+}
namespace BaseClassOffsets {
struct A { int a; };
More information about the cfe-commits
mailing list