Skip to content

Commit dfbe827

Browse files
committed
[CIR][CIRGen] Handle one more case of VisitCompoundLiteralExpr for aggregates
1 parent 33b67ca commit dfbe827

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
822822
bool Destruct =
823823
!CGF.getLangOpts().CPlusPlus && !Slot.isExternallyDestructed();
824824
if (Destruct)
825-
llvm_unreachable("NYI");
825+
Slot.setExternallyDestructed();
826826

827827
CGF.buildAggExpr(E->getInitializer(), Slot);
828828

clang/test/CIR/CodeGen/compound-literal.c

+43-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -S -emit-llvm %s -o %t.ll
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -S -emit-llvm %s -o %t.ll
44
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
55

66

@@ -52,7 +52,7 @@ struct G g(int x, int y, int z) {
5252
}
5353

5454
// CIR: cir.func @g
55-
// CIR: %[[RETVAL:.*]] = cir.alloca !ty_22G22, !cir.ptr<!ty_22G22>, ["__retval"] {alignment = 2 : i64} loc(#loc18)
55+
// CIR: %[[RETVAL:.*]] = cir.alloca !ty_22G22, !cir.ptr<!ty_22G22>, ["__retval"] {alignment = 2 : i64}
5656
// CIR: %[[X:.*]] = cir.get_member %[[RETVAL]][0] {name = "x"}
5757
// CIR: cir.store {{.*}}, %[[X]] : !s16i
5858
// CIR: %[[Y:.*]] = cir.get_member %[[RETVAL]][1] {name = "y"}
@@ -64,4 +64,43 @@ struct G g(int x, int y, int z) {
6464

6565
// Nothing meaningful to test for LLVM codegen here.
6666
// FIXME: ABI note, LLVM lowering differs from traditional LLVM codegen here,
67-
// because the former does a memcopy + i48 load.
67+
// because the former does a memcopy + i48 load.
68+
69+
typedef struct { unsigned long pgprot; } pgprot_t;
70+
void split_large_page(unsigned long addr, pgprot_t prot)
71+
{
72+
(addr ? prot : ((pgprot_t) { 0x001 } )).pgprot;
73+
}
74+
75+
// CIR-LABEL: @split_large_page
76+
// CIR: %[[VAL_2:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["addr", init] {alignment = 8 : i64}
77+
// CIR: %[[VAL_3:.*]] = cir.alloca !ty_22pgprot_t22, !cir.ptr<!ty_22pgprot_t22>, ["prot", init] {alignment = 8 : i64}
78+
// CIR: %[[VAL_4:.*]] = cir.alloca !ty_22pgprot_t22, !cir.ptr<!ty_22pgprot_t22>, ["tmp"] {alignment = 8 : i64}
79+
// CIR: cir.store {{.*}}, %[[VAL_2]] : !u64i, !cir.ptr<!u64i>
80+
// CIR: cir.store {{.*}}, %[[VAL_3]] : !ty_22pgprot_t22, !cir.ptr<!ty_22pgprot_t22>
81+
// CIR: %[[VAL_5:.*]] = cir.load %[[VAL_2]] : !cir.ptr<!u64i>, !u64i
82+
// CIR: %[[VAL_6:.*]] = cir.cast(int_to_bool, %[[VAL_5]] : !u64i), !cir.bool
83+
// CIR: cir.if %[[VAL_6]] {
84+
// CIR: cir.copy %[[VAL_3]] to %[[VAL_4]] : !cir.ptr<!ty_22pgprot_t22>
85+
// CIR: } else {
86+
// CIR: %[[VAL_7:.*]] = cir.get_member %[[VAL_4]][0] {name = "pgprot"} : !cir.ptr<!ty_22pgprot_t22> -> !cir.ptr<!u64i>
87+
// CIR: %[[VAL_8:.*]] = cir.const #cir.int<1> : !s32i
88+
// CIR: %[[VAL_9:.*]] = cir.cast(integral, %[[VAL_8]] : !s32i), !u64i
89+
// CIR: cir.store %[[VAL_9]], %[[VAL_7]] : !u64i, !cir.ptr<!u64i>
90+
// CIR: }
91+
// CIR: %[[VAL_10:.*]] = cir.get_member %[[VAL_4]][0] {name = "pgprot"} : !cir.ptr<!ty_22pgprot_t22> -> !cir.ptr<!u64i>
92+
// CIR: %[[VAL_11:.*]] = cir.load %[[VAL_10]] : !cir.ptr<!u64i>, !u64i
93+
// CIR: cir.return
94+
// CIR: }
95+
96+
// CHECK-LABEL: @split_large_page
97+
// CHECK: br i1 {{.*}}, label %[[TRUE:[a-z0-9]+]], label %[[FALSE:[a-z0-9]+]]
98+
// CHECK: [[FALSE]]:
99+
// CHECK: %[[GEP:.*]] = getelementptr {{.*}}, ptr %[[ADDR:.*]], i32 0, i32 0
100+
// CHECK: store i64 1, ptr %[[GEP]], align 8
101+
// CHECK: br label %[[EXIT:[a-z0-9]+]]
102+
// CHECK: [[TRUE]]:
103+
// CHECK: call void @llvm.memcpy.p0.p0.i32(ptr %[[ADDR]], ptr {{.*}}, i32 8, i1 false)
104+
// CHECK: br label %[[EXIT]]
105+
// CHECK: [[EXIT]]:
106+
// CHECK: ret void

0 commit comments

Comments
 (0)