1 // RUN: %clang_cc1 -no-opaque-pointers -std=c++2a -S -emit-llvm -o - -disable-llvm-passes -triple x86_64-apple-macos10.14 %s | FileCheck %s
3 void test_scalar(int &oper
) {
4 // CHECK-LABEL: define{{.*}} void @_Z11test_scalarRi
5 __builtin_bit_cast(float, oper
);
7 // CHECK: [[OPER:%.*]] = alloca i32*
8 // CHECK: [[REF:%.*]] = load i32*, i32**
9 // CHECK-NEXT: [[CASTED:%.*]] = bitcast i32* [[REF]] to float*
10 // CHECK-NEXT: load float, float* [[CASTED]]
18 unsigned long test_aggregate_to_scalar(two_ints
&ti
) {
19 // CHECK-LABEL: define{{.*}} i64 @_Z24test_aggregate_to_scalarR8two_ints
20 return __builtin_bit_cast(unsigned long, ti
);
22 // CHECK: [[TI_ADDR:%.*]] = alloca %struct.two_ints*, align 8
23 // CHECK: [[TI_LOAD:%.*]] = load %struct.two_ints*, %struct.two_ints** [[TI_ADDR]]
24 // CHECK-NEXT: [[CASTED:%.*]] = bitcast %struct.two_ints* [[TI_LOAD]] to i64*
25 // CHECK-NEXT: load i64, i64* [[CASTED]]
33 two_floats
test_aggregate_record(two_ints
& ti
) {
34 // CHECK-LABEL: define{{.*}} <2 x float> @_Z21test_aggregate_recordR8two_int
35 return __builtin_bit_cast(two_floats
, ti
);
37 // CHECK: [[RETVAL:%.*]] = alloca %struct.two_floats, align 4
38 // CHECK: [[TI:%.*]] = alloca %struct.two_ints*, align 8
40 // CHECK: [[LOAD_TI:%.*]] = load %struct.two_ints*, %struct.two_ints** [[TI]]
41 // CHECK: [[MEMCPY_SRC:%.*]] = bitcast %struct.two_ints* [[LOAD_TI]] to i8*
42 // CHECK: [[MEMCPY_DST:%.*]] = bitcast %struct.two_floats* [[RETVAL]] to i8*
43 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[MEMCPY_DST]], i8* align 4 [[MEMCPY_SRC]]
46 two_floats
test_aggregate_array(int (&ary
)[2]) {
47 // CHECK-LABEL: define{{.*}} <2 x float> @_Z20test_aggregate_arrayRA2_i
48 return __builtin_bit_cast(two_floats
, ary
);
50 // CHECK: [[RETVAL:%.*]] = alloca %struct.two_floats, align 4
51 // CHECK: [[ARY:%.*]] = alloca [2 x i32]*, align 8
53 // CHECK: [[LOAD_ARY:%.*]] = load [2 x i32]*, [2 x i32]** [[ARY]]
54 // CHECK: [[MEMCPY_SRC:%.*]] = bitcast [2 x i32]* [[LOAD_ARY]] to i8*
55 // CHECK: [[MEMCPY_DST:%.*]] = bitcast %struct.two_floats* [[RETVAL]] to i8*
56 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[MEMCPY_DST]], i8* align 4 [[MEMCPY_SRC]]
59 two_ints
test_scalar_to_aggregate(unsigned long ul
) {
60 // CHECK-LABEL: define{{.*}} i64 @_Z24test_scalar_to_aggregatem
61 return __builtin_bit_cast(two_ints
, ul
);
63 // CHECK: [[TI:%.*]] = alloca %struct.two_ints, align 4
64 // CHECK: [[TITMP:%.*]] = bitcast %struct.two_ints* [[TI]] to i8*
65 // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[TITMP]]
68 unsigned long test_complex(_Complex
unsigned &cu
) {
69 // CHECK-LABEL: define{{.*}} i64 @_Z12test_complexRCj
70 return __builtin_bit_cast(unsigned long, cu
);
72 // CHECK: [[REF_ALLOCA:%.*]] = alloca { i32, i32 }*, align 8
73 // CHECK-NEXT: store { i32, i32 }* {{.*}}, { i32, i32 }** [[REF_ALLOCA]]
74 // CHECK-NEXT: [[REF:%.*]] = load { i32, i32 }*, { i32, i32 }** [[REF_ALLOCA]]
75 // CHECK-NEXT: [[CASTED:%.*]] = bitcast { i32, i32 }* [[REF]] to i64*
76 // CHECK-NEXT: load i64, i64* [[CASTED]], align 4
79 _Complex
unsigned test_to_complex(unsigned long &ul
) {
80 // CHECK-LABEL: define{{.*}} i64 @_Z15test_to_complexRm
82 return __builtin_bit_cast(_Complex
unsigned, ul
);
84 // CHECK: [[REF:%.*]] = alloca i64*
85 // CHECK: [[LOAD_REF:%.*]] = load i64*, i64** [[REF]]
86 // CHECK: [[CASTED:%.*]] = bitcast i64* [[LOAD_REF]] to { i32, i32 }*
89 unsigned long test_array(int (&ary
)[2]) {
90 // CHECK-LABEL: define{{.*}} i64 @_Z10test_arrayRA2_i
91 return __builtin_bit_cast(unsigned long, ary
);
93 // CHECK: [[REF_ALLOCA:%.*]] = alloca [2 x i32]*
94 // CHECK: [[LOAD_REF:%.*]] = load [2 x i32]*, [2 x i32]** [[REF_ALLOCA]]
95 // CHECK: [[CASTED:%.*]] = bitcast [2 x i32]* [[LOAD_REF]] to i64*
96 // CHECK: load i64, i64* [[CASTED]], align 4
99 two_ints
test_rvalue_aggregate() {
100 // CHECK-LABEL: define{{.*}} i64 @_Z21test_rvalue_aggregate
101 return __builtin_bit_cast(two_ints
, 42ul);
103 // CHECK: [[TI:%.*]] = alloca %struct.two_ints, align 4
104 // CHECK: [[CASTED:%.*]] = bitcast %struct.two_ints* [[TI]] to i8*
105 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[CASTED]]