120 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG7 8int foo() {9 int e = (int){1};10 return e;11}12 13// CIR: %[[RET:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]14// CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]15// CIR: %[[COMPOUND:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, [".compoundliteral", init]16// CIR: %[[VALUE:.*]] = cir.const #cir.int<1> : !s32i17// CIR: cir.store{{.*}} %[[VALUE]], %[[COMPOUND]] : !s32i, !cir.ptr<!s32i>18// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPOUND]] : !cir.ptr<!s32i>, !s32i19// CIR: cir.store{{.*}} %[[TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>20// CIR: %[[TMP_2:.*]] = cir.load{{.*}} %[[INIT]] : !cir.ptr<!s32i>, !s32i21// CIR: cir.store %[[TMP_2]], %[[RET]] : !s32i, !cir.ptr<!s32i>22// CIR: %[[TMP_3:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i23// CIR: cir.return %[[TMP_3]] : !s32i24 25// LLVM: %[[RET:.*]] = alloca i32, i64 1, align 426// LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 427// LLVM: %[[COMPOUND:.*]] = alloca i32, i64 1, align 428// LLVM: store i32 1, ptr %[[COMPOUND]], align 429// LLVM: %[[TMP:.*]] = load i32, ptr %[[COMPOUND]], align 430// LLVM: store i32 %[[TMP]], ptr %[[INIT]], align 431// LLVM: %[[TMP_2:.*]] = load i32, ptr %[[INIT]], align 432// LLVM: store i32 %[[TMP_2]], ptr %[[RET]], align 433// LLVM: %[[TMP_3:.*]] = load i32, ptr %[[RET]], align 434// LLVM: ret i32 %[[TMP_3]]35 36// OGCG: %[[INIT:.*]] = alloca i32, align 437// OGCG: %[[COMPOUND:.*]] = alloca i32, align 438// OGCG: store i32 1, ptr %[[COMPOUND]], align 439// OGCG: %[[TMP:.*]] = load i32, ptr %[[COMPOUND]], align 440// OGCG: store i32 %[[TMP]], ptr %[[INIT]], align 441// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[INIT]], align 442// OGCG: ret i32 %[[TMP_2]]43 44void foo2() {45 int _Complex a = (int _Complex) { 1, 2};46}47 48// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]49// CIR: %[[CL_ADDR:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, [".compoundliteral"]50// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<1> : !s32i, #cir.int<2> : !s32i> : !cir.complex<!s32i>51// CIR: cir.store{{.*}} %[[COMPLEX]], %[[CL_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>52// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[CL_ADDR]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>53// CIR: cir.store{{.*}} %[[TMP]], %[[A_ADDR]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>54 55// LLVM: %[[A_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 456// LLVM: %[[CL_ADDR:.*]] = alloca { i32, i32 }, i64 1, align 457// LLVM: store { i32, i32 } { i32 1, i32 2 }, ptr %[[CL_ADDR]], align 458// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[CL_ADDR]], align 459// LLVM: store { i32, i32 } %[[TMP]], ptr %[[A_ADDR]], align 460 61// OGCG: %[[A_ADDR:.*]] = alloca { i32, i32 }, align 462// OGCG: %[[CL_ADDR:.*]] = alloca { i32, i32 }, align 463// OGCG: %[[CL_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[CL_ADDR]], i32 0, i32 064// OGCG: %[[CL_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[CL_ADDR]], i32 0, i32 165// OGCG: store i32 1, ptr %[[CL_REAL_PTR]], align 466// OGCG: store i32 2, ptr %[[CL_IMAG_PTR]], align 467// OGCG: %[[CL_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[CL_ADDR]], i32 0, i32 068// OGCG: %[[CL_REAL:.*]] = load i32, ptr %[[CL_REAL_PTR]], align 469// OGCG: %[[CL_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[CL_ADDR]], i32 0, i32 170// OGCG: %[[CL_IMAG:.*]] = load i32, ptr %[[CL_IMAG_PTR]], align 471// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[A_ADDR]], i32 0, i32 072// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[A_ADDR]], i32 0, i32 173// OGCG: store i32 %[[CL_REAL]], ptr %[[A_REAL_PTR]], align 474// OGCG: store i32 %[[CL_IMAG]], ptr %[[A_IMAG_PTR]], align 475 76void foo3() {77 typedef int vi4 __attribute__((vector_size(16)));78 auto a = (vi4){10, 20, 30, 40};79}80 81// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a", init]82// CIR: %[[VEC:.*]] = cir.const #cir.const_vector<[#cir.int<10> : !s32i, #cir.int<20> : !s32i, #cir.int<30> : !s32i, #cir.int<40> : !s32i]> : !cir.vector<4 x !s32i>83// CIR: cir.store{{.*}} %[[VEC]], %[[A_ADDR]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>84 85// LLVM: %[[A_ADDR:.*]] = alloca <4 x i32>, i64 1, align 1686// LLVM: store <4 x i32> <i32 10, i32 20, i32 30, i32 40>, ptr %[[A_ADDR]], align 1687 88// FIXME: OGCG emits a temporary compound literal in this case because it omits89// vector types from the check for aggregate constants in90// EmitAutoVarAlloca. This looks like an oversight in OGCG because the91// code to emit a constant in EmitStoresForConstant specifically looks92// for vector types in OGCG.93 94// OGCG: %[[A_ADDR:.*]] = alloca <4 x i32>, align 1695// OGCG: %[[CL_ADDR:.*]] = alloca <4 x i32>, align 1696// OGCG: store <4 x i32> <i32 10, i32 20, i32 30, i32 40>, ptr %[[CL_ADDR]], align 1697// OGCG: %[[TMP:.*]] = load <4 x i32>, ptr %[[CL_ADDR]], align 1698// OGCG: store <4 x i32> %[[TMP]], ptr %[[A_ADDR]], align 1699 100struct Point {101 int x, y;102};103 104void foo4() {105 Point p = (Point){5, 10};106}107 108// CIR-LABEL: @_Z4foo4v109// CIR: %[[P:.*]] = cir.alloca !rec_Point, !cir.ptr<!rec_Point>, ["p", init]110// CIR: %[[CONST:.*]] = cir.const #cir.const_record<{#cir.int<5> : !s32i, #cir.int<10> : !s32i}> : !rec_Point111// CIR: cir.store{{.*}} %[[CONST]], %[[P]] : !rec_Point, !cir.ptr<!rec_Point>112 113// LLVM-LABEL: @_Z4foo4v114// LLVM: %[[P:.*]] = alloca %struct.Point115// LLVM: store %struct.Point { i32 5, i32 10 }, ptr %[[P]], align 4116 117// OGCG-LABEL: @_Z4foo4v118// OGCG: %[[P:.*]] = alloca %struct.Point119// OGCG: call void @llvm.memcpy{{.*}}(ptr{{.*}} %[[P]], ptr{{.*}} @__const._Z4foo4v.p120