[clang] [clang][bytecode] Fix a crash in codegen (PR #151515)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 31 06:16:36 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/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.
>From 017dbd3c73c3db82fbc8d6a21d74a21b7891ee01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 31 Jul 2025 15:14:55 +0200
Subject: [PATCH] [clang][bytecode] Fix a crash in codegen
getRecord() can return nullptr if any one of the fields does, in this
case because the array is too large for us to allocate.
---
clang/lib/AST/ByteCode/Compiler.cpp | 3 +++
clang/test/AST/ByteCode/codegen.cpp | 4 ++++
2 files changed, 7 insertions(+)
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