Skip to content

Commit f4aaf6f

Browse files
authored
[clang][bytecode] Fix a crash in codegen (llvm#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.
1 parent 311b291 commit f4aaf6f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,9 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
17581758
if (Inits.size() == 1 && E->getType() == Inits[0]->getType())
17591759
return this->delegate(Inits[0]);
17601760

1761+
if (!R)
1762+
return false;
1763+
17611764
auto initPrimitiveField = [=](const Record::Field *FieldToInit,
17621765
const Expr *Init, PrimType T,
17631766
bool Activate = false) -> bool {

clang/test/AST/ByteCode/codegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ S s;
2323
// CHECK: @sp = constant ptr getelementptr (i8, ptr @s, i64 16), align 8
2424
float &sp = s.c[3];
2525

26+
namespace NearlyZeroInit {
27+
// CHECK: @_ZN14NearlyZeroInit1bE ={{.*}} global{{.*}} { i32, <{ i32, [2147483647 x i32] }> } { i32 1, <{ i32, [2147483647 x i32] }> <{ i32 2, [2147483647 x i32] zeroinitializer }> }{{.*}}
28+
struct B { int n; int arr[1024 * 1024 * 1024 * 2u]; } b = {1, {2}};
29+
}
2630

2731
namespace BaseClassOffsets {
2832
struct A { int a; };

0 commit comments

Comments
 (0)