blob: 5e32480d71d6b27141c0938bf77ed76b6d853545 [file] [edit]
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
// RUN: FileCheck --check-prefix=LLVM,LLVMCIR --input-file=%t-cir.ll %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
// RUN: FileCheck --check-prefix=LLVM,OGCG --input-file=%t.ll %s
typedef union vec3 {
struct { double x, y, z; };
double component[3];
} vec3;
// LLVMCIR: @__const.ret_outer.__retval = {{.*}}%struct.outer { %union.needs_padding zeroinitializer, i32 1 }
// OGCG: @__const.ret_outer.o = {{.*}}{ { i32, [4 x i8] }, i32, [4 x i8] } { { i32, [4 x i8] } zeroinitializer, i32 1, [4 x i8] zeroinitializer }
// CIR: cir.global "private" constant cir_private @__const.ret_outer.__retval = #cir.const_record<{#cir.zero : !rec_needs_padding, #cir.int<1> : !s32i}> : !rec_outer
// In C mode, this does do zero padding.
vec3 ret_vec3() {
// CIR-LABEL: ret_vec3
// CIR: %[[RET_ALLOCA:.*]] = cir.alloca "__retval" {{.*}} : !cir.ptr<!rec_vec3>
// CIR: %[[GET_ANON:.*]] = cir.get_member %[[RET_ALLOCA]][0] {name = ""}
// CIR: %[[GET_X:.*]] = cir.get_member %[[GET_ANON]][0] {name = "x"}
// CIR: %[[FIVE:.*]] = cir.const #cir.fp<5.{{.*}}> : !cir.double
// CIR: cir.store{{.*}} %[[FIVE]], %[[GET_X]]
// CIR: %[[GET_Y:.*]] = cir.get_member %[[GET_ANON]][1] {name = "y"}
// CIR: %[[ZERO:.*]] = cir.const #cir.fp<0.{{.*}}> : !cir.double
// CIR: cir.store{{.*}} %[[ZERO]], %[[GET_Y]]
// CIR: %[[GET_Z:.*]] = cir.get_member %[[GET_ANON]][2] {name = "z"}
// CIR: %[[ZERO:.*]] = cir.const #cir.fp<0.{{.*}}> : !cir.double
// CIR: cir.store{{.*}} %[[ZERO]], %[[GET_Z]]
// LLVM-LABEL: ret_vec3
// OGCG-SAME: ptr{{.*}}sret(%union.vec3){{.*}}%[[RET_ALLOCA:.*]])
// LLVMCIR: %[[RET_ALLOCA:.*]] = alloca %union.vec3
// LLVM: %[[GET_X:.*]] = getelementptr {{.*}}, ptr %[[RET_ALLOCA]], i32 0, i32 0
// LLVM: store double 5{{.*}}, ptr %[[GET_X]]
// LLVM: %[[GET_Y:.*]] = getelementptr {{.*}}, ptr %[[RET_ALLOCA]], i32 0, i32 1
// LLVM: store double 0{{.*}}, ptr %[[GET_Y]]
// LLVM: %[[GET_Z:.*]] = getelementptr {{.*}}, ptr %[[RET_ALLOCA]], i32 0, i32 2
// LLVM: store double 0{{.*}}, ptr %[[GET_Z]]
return (vec3) {{ .x = 5.0 }};
}
union needs_padding {
int a;
long long b;
};
struct outer {
union needs_padding np;
int x;
};
struct outer ret_outer() {
struct outer o = {{}, 1};
return o;
// CIR-LABEL: ret_outer
// CIR: %[[RET_ALLOCA:.*]] = cir.alloca "__retval" {{.*}} init : !cir.ptr<!rec_outer>
// CIR: %[[GET_GLOB:.*]] = cir.get_global @__const.ret_outer.__retval : !cir.ptr<!rec_outer>
// CIR: cir.copy %[[GET_GLOB]] to %[[RET_ALLOCA]] : !cir.ptr<!rec_outer>
// LLVM-LABEL: ret_outer
// LLVM: %[[RET_ALLOCA:.*]] = alloca %struct.outer
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr {{.*}}%[[RET_ALLOCA]], ptr {{.*}}@__const.ret_outer.{{.*}}, i64 16, i1 false)
}