Skip to content

Commit 4a2757d

Browse files
committed
Make globals used for array initialization codegen constant
As pointed out in D133835 these globals will never be written to (they're only used for trivially copyable types), so they can always be constant. Differential revision: https://reviews.llvm.org/D146211
1 parent c21790d commit 4a2757d

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
532532
Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
533533
auto GV = new llvm::GlobalVariable(
534534
CGM.getModule(), C->getType(),
535-
CGM.isTypeConstant(ArrayQTy, /* ExcludeCtor= */ true,
536-
/* ExcludeDtor= */ false),
537-
llvm::GlobalValue::PrivateLinkage, C, "constinit",
535+
/* isConstant= */ true, llvm::GlobalValue::PrivateLinkage, C,
536+
"constinit",
538537
/* InsertBefore= */ nullptr, llvm::GlobalVariable::NotThreadLocal,
539538
CGM.getContext().getTargetAddressSpace(AS));
540539
Emitter.finalize(GV);

clang/test/CodeGen/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ unsigned v2[2][3] = {[0 ... 1][0 ... 1] = 2222, 3333};
1010

1111
// CHECK-DAG: [1 x %struct.M] [%struct.M { [2 x %struct.I] [%struct.I { [3 x i32] [i32 4, i32 4, i32 0] }, %struct.I { [3 x i32] [i32 4, i32 4, i32 5] }] }],
1212
// CHECK-DAG: [2 x [3 x i32]] {{[[][[]}}3 x i32] [i32 2222, i32 2222, i32 0], [3 x i32] [i32 2222, i32 2222, i32 3333]],
13-
// CHECK-DAG: [[INIT14:.*]] = private global [16 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 17, i32 17, i32 17, i32 17, i32 17, i32 17, i32 17, i32 0, i32 0, i32 0, i32 0], align 4
13+
// CHECK-DAG: [[INIT14:.*]] = private constant [16 x i32] [i32 0, i32 0, i32 0, i32 0, i32 0, i32 17, i32 17, i32 17, i32 17, i32 17, i32 17, i32 17, i32 0, i32 0, i32 0, i32 0], align 4
1414

1515
void f1(void) {
1616
// Scalars in braces.

clang/test/CodeGen/label-array-aggregate-init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm %s -o - | FileCheck %s
22

3-
// CHECK: @constinit = private global [3 x ptr] [ptr blockaddress(@main, %L), ptr null, ptr null]
3+
// CHECK: @constinit = private constant [3 x ptr] [ptr blockaddress(@main, %L), ptr null, ptr null]
44

55
void receivePtrs(void **);
66

0 commit comments

Comments
 (0)