Skip to content

Commit 29d3232

Browse files
committed
[CIR] Add missing testcase for previous commit
1 parent ad02f92 commit 29d3232

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

clang/test/CIR/CodeGen/global-new.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=CIR_BEFORE
2+
// RUN: FileCheck %s -check-prefix=CIR_AFTER --input-file=%t.cir
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
4+
// RUN: FileCheck %s -check-prefix=LLVM --input-file=%t.ll
5+
6+
struct e { e(int); };
7+
e *g = new e(0);
8+
9+
// CIR_BEFORE: ![[ty:.*]] = !cir.struct<struct "e" {!cir.int<u, 8>}
10+
11+
// CIR_BEFORE: cir.global external @g = ctor : !cir.ptr<![[ty]]> {
12+
// CIR_BEFORE: %[[GlobalAddr:.*]] = cir.get_global @g : !cir.ptr<!cir.ptr<![[ty]]>>
13+
// CIR_BEFORE: %[[Size:.*]] = cir.const #cir.int<1> : !u64i
14+
// CIR_BEFORE: %[[NewAlloc:.*]] = cir.call @_Znwm(%[[Size]]) : (!u64i) -> !cir.ptr<!void>
15+
// CIR_BEFORE: %[[NewCasted:.*]] = cir.cast(bitcast, %[[NewAlloc]] : !cir.ptr<!void>), !cir.ptr<![[ty]]>
16+
// CIR_BEFORE: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i
17+
// CIR_BEFORE: cir.call @_ZN1eC1Ei(%[[NewCasted]], %[[ZERO]]) : (!cir.ptr<![[ty]]>, !s32i) -> ()
18+
// CIR_BEFORE: cir.store %3, %[[GlobalAddr]] : !cir.ptr<![[ty]]>, !cir.ptr<!cir.ptr<![[ty]]>>
19+
// CIR_BEFORE: }
20+
21+
// CIR_AFTER: {{%.*}} = cir.const #cir.int<1> : !u64i
22+
// CIR_AFTER: {{%.*}} = cir.call @_Znwm(%1) : (!u64i) -> !cir.ptr<!void>
23+
24+
// LLVM-DAG: @llvm.global_ctors = appending constant [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65536, ptr @__cxx_global_var_init, ptr null }]
25+
// LLVM: define internal void @__cxx_global_var_init()
26+
// LLVM: call ptr @_Znwm(i64 1)
27+
28+
// LLVM: define void @_GLOBAL__sub_I_global_new.cpp()
29+
// LLVM: call void @__cxx_global_var_init()

0 commit comments

Comments
 (0)