[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGen / complex-strictfp.c
blobb0c84d5eebe725626d27b5b0193b9a5425e6234f
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -ffp-exception-behavior=maytrap -emit-llvm -o - %s | FileCheck --implicit-check-not=fpexcept.maytrap --implicit-check-not=round.tonearest %s
5 // Test that the constrained intrinsics are picking up the exception
6 // metadata from the AST instead of the global default from the command line.
7 // Include rounding metadata in the testing.
8 // Any cases of "fpexcept.maytrap" in this test are clang bugs.
9 // Any cases of "round.tonearest" in this test are clang bugs.
11 #pragma float_control(except, on)
12 #pragma STDC FENV_ROUND FE_UPWARD
14 _Complex double g1, g2;
15 _Complex float cf;
16 double D;
18 // CHECK-LABEL: @test3a(
19 // CHECK-NEXT: entry:
20 // CHECK-NEXT: [[TMP0:%.*]] = load double, ptr @D, align 8
21 // CHECK-NEXT: [[CF_REAL:%.*]] = load float, ptr @cf, align 4
22 // CHECK-NEXT: [[CF_IMAG:%.*]] = load float, ptr getelementptr inbounds ({ float, float }, ptr @cf, i32 0, i32 1), align 4
23 // CHECK-NEXT: [[CONV:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float [[CF_REAL]], metadata !"fpexcept.strict") #[[ATTR2:[0-9]+]]
24 // CHECK-NEXT: [[CONV1:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float [[CF_IMAG]], metadata !"fpexcept.strict") #[[ATTR2]]
25 // CHECK-NEXT: [[ADD_R:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double [[CONV]], double [[TMP0]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
26 // CHECK-NEXT: [[CONV2:%.*]] = call float @llvm.experimental.constrained.fptrunc.f32.f64(double [[ADD_R]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
27 // CHECK-NEXT: [[CONV3:%.*]] = call float @llvm.experimental.constrained.fptrunc.f32.f64(double [[CONV1]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
28 // CHECK-NEXT: store float [[CONV2]], ptr @cf, align 4
29 // CHECK-NEXT: store float [[CONV3]], ptr getelementptr inbounds ({ float, float }, ptr @cf, i32 0, i32 1), align 4
30 // CHECK-NEXT: ret void
32 void test3a(void) {
33 cf += D;
36 // CHECK-LABEL: @test3b(
37 // CHECK-NEXT: entry:
38 // CHECK-NEXT: [[CF_REAL:%.*]] = load float, ptr @cf, align 4
39 // CHECK-NEXT: [[CF_IMAG:%.*]] = load float, ptr getelementptr inbounds ({ float, float }, ptr @cf, i32 0, i32 1), align 4
40 // CHECK-NEXT: [[CONV:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float [[CF_REAL]], metadata !"fpexcept.strict") #[[ATTR2]]
41 // CHECK-NEXT: [[CONV1:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float [[CF_IMAG]], metadata !"fpexcept.strict") #[[ATTR2]]
42 // CHECK-NEXT: [[TMP0:%.*]] = load double, ptr @D, align 8
43 // CHECK-NEXT: [[ADD_R:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double [[TMP0]], double [[CONV]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
44 // CHECK-NEXT: store double [[ADD_R]], ptr @D, align 8
45 // CHECK-NEXT: ret void
47 void test3b(void) {
48 D += cf;
51 // CHECK-LABEL: @test3c(
52 // CHECK-NEXT: entry:
53 // CHECK-NEXT: [[G1_REAL:%.*]] = load double, ptr @g1, align 8
54 // CHECK-NEXT: [[G1_IMAG:%.*]] = load double, ptr getelementptr inbounds ({ double, double }, ptr @g1, i32 0, i32 1), align 8
55 // CHECK-NEXT: [[CF_REAL:%.*]] = load float, ptr @cf, align 4
56 // CHECK-NEXT: [[CF_IMAG:%.*]] = load float, ptr getelementptr inbounds ({ float, float }, ptr @cf, i32 0, i32 1), align 4
57 // CHECK-NEXT: [[CONV:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float [[CF_REAL]], metadata !"fpexcept.strict") #[[ATTR2]]
58 // CHECK-NEXT: [[CONV1:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float [[CF_IMAG]], metadata !"fpexcept.strict") #[[ATTR2]]
59 // CHECK-NEXT: [[CALL:%.*]] = call { double, double } @__divdc3(double noundef [[CONV]], double noundef [[CONV1]], double noundef [[G1_REAL]], double noundef [[G1_IMAG]]) #[[ATTR3:[0-9]+]]
60 // CHECK-NEXT: [[TMP0:%.*]] = extractvalue { double, double } [[CALL]], 0
61 // CHECK-NEXT: [[TMP1:%.*]] = extractvalue { double, double } [[CALL]], 1
62 // CHECK-NEXT: [[CONV2:%.*]] = call float @llvm.experimental.constrained.fptrunc.f32.f64(double [[TMP0]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
63 // CHECK-NEXT: [[CONV3:%.*]] = call float @llvm.experimental.constrained.fptrunc.f32.f64(double [[TMP1]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
64 // CHECK-NEXT: store float [[CONV2]], ptr @cf, align 4
65 // CHECK-NEXT: store float [[CONV3]], ptr getelementptr inbounds ({ float, float }, ptr @cf, i32 0, i32 1), align 4
66 // CHECK-NEXT: ret void
68 void test3c(void) {
69 cf /= g1;
72 // CHECK-LABEL: @test3d(
73 // CHECK-NEXT: entry:
74 // CHECK-NEXT: [[G1_REAL:%.*]] = load double, ptr @g1, align 8
75 // CHECK-NEXT: [[G1_IMAG:%.*]] = load double, ptr getelementptr inbounds ({ double, double }, ptr @g1, i32 0, i32 1), align 8
76 // CHECK-NEXT: [[TMP0:%.*]] = load double, ptr @D, align 8
77 // CHECK-NEXT: [[ADD_R:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double [[G1_REAL]], double [[TMP0]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
78 // CHECK-NEXT: store double [[ADD_R]], ptr @g1, align 8
79 // CHECK-NEXT: store double [[G1_IMAG]], ptr getelementptr inbounds ({ double, double }, ptr @g1, i32 0, i32 1), align 8
80 // CHECK-NEXT: ret void
82 void test3d(void) {
83 g1 = g1 + D;
86 // CHECK-LABEL: @test3e(
87 // CHECK-NEXT: entry:
88 // CHECK-NEXT: [[TMP0:%.*]] = load double, ptr @D, align 8
89 // CHECK-NEXT: [[G1_REAL:%.*]] = load double, ptr @g1, align 8
90 // CHECK-NEXT: [[G1_IMAG:%.*]] = load double, ptr getelementptr inbounds ({ double, double }, ptr @g1, i32 0, i32 1), align 8
91 // CHECK-NEXT: [[ADD_R:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double [[TMP0]], double [[G1_REAL]], metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
92 // CHECK-NEXT: store double [[ADD_R]], ptr @g1, align 8
93 // CHECK-NEXT: store double [[G1_IMAG]], ptr getelementptr inbounds ({ double, double }, ptr @g1, i32 0, i32 1), align 8
94 // CHECK-NEXT: ret void
96 void test3e(void) {
97 g1 = D + g1;
100 // CHECK-LABEL: @t1(
101 // CHECK-NEXT: entry:
102 // CHECK-NEXT: [[CONV:%.*]] = call float @llvm.experimental.constrained.fptrunc.f32.f64(double 4.000000e+00, metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
103 // CHECK-NEXT: store float [[CONV]], ptr @cf, align 4
104 // CHECK-NEXT: ret void
106 void t1(void) {
107 (__real__ cf) = 4.0;
110 // CHECK-LABEL: @t2(
111 // CHECK-NEXT: entry:
112 // CHECK-NEXT: [[CONV:%.*]] = call float @llvm.experimental.constrained.fptrunc.f32.f64(double 4.000000e+00, metadata !"round.upward", metadata !"fpexcept.strict") #[[ATTR2]]
113 // CHECK-NEXT: store float [[CONV]], ptr getelementptr inbounds ({ float, float }, ptr @cf, i32 0, i32 1), align 4
114 // CHECK-NEXT: ret void
116 void t2(void) {
117 (__imag__ cf) = 4.0;
120 // CHECK-LABEL: @t91(
121 // CHECK-NEXT: entry:
122 // CHECK-NEXT: [[C:%.*]] = alloca [0 x i8], align 1
123 // CHECK-NEXT: br i1 false, label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
124 // CHECK: cond.true:
125 // CHECK-NEXT: [[CONV:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float 2.000000e+00, metadata !"fpexcept.strict") #[[ATTR2]]
126 // CHECK-NEXT: br label [[COND_END:%.*]]
127 // CHECK: cond.false:
128 // CHECK-NEXT: [[CONV1:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float 2.000000e+00, metadata !"fpexcept.strict") #[[ATTR2]]
129 // CHECK-NEXT: br label [[COND_END]]
130 // CHECK: cond.end:
131 // CHECK-NEXT: [[COND_R:%.*]] = phi double [ [[CONV]], [[COND_TRUE]] ], [ [[CONV1]], [[COND_FALSE]] ]
132 // CHECK-NEXT: [[COND_I:%.*]] = phi double [ 0.000000e+00, [[COND_TRUE]] ], [ 0.000000e+00, [[COND_FALSE]] ]
133 // CHECK-NEXT: ret void
135 void t91(void) {
136 // Check for proper type promotion of conditional expression
137 char c[(int)(sizeof(typeof((0 ? 2.0f : (_Complex double) 2.0f))) - sizeof(_Complex double))];
138 // Check for proper codegen
139 (0 ? 2.0f : (_Complex double) 2.0f);
142 // CHECK-LABEL: @t92(
143 // CHECK-NEXT: entry:
144 // CHECK-NEXT: [[C:%.*]] = alloca [0 x i8], align 1
145 // CHECK-NEXT: br i1 false, label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
146 // CHECK: cond.true:
147 // CHECK-NEXT: [[CONV:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float 2.000000e+00, metadata !"fpexcept.strict") #[[ATTR2]]
148 // CHECK-NEXT: br label [[COND_END:%.*]]
149 // CHECK: cond.false:
150 // CHECK-NEXT: [[CONV1:%.*]] = call double @llvm.experimental.constrained.fpext.f64.f32(float 2.000000e+00, metadata !"fpexcept.strict") #[[ATTR2]]
151 // CHECK-NEXT: br label [[COND_END]]
152 // CHECK: cond.end:
153 // CHECK-NEXT: [[COND_R:%.*]] = phi double [ [[CONV]], [[COND_TRUE]] ], [ [[CONV1]], [[COND_FALSE]] ]
154 // CHECK-NEXT: [[COND_I:%.*]] = phi double [ 0.000000e+00, [[COND_TRUE]] ], [ 0.000000e+00, [[COND_FALSE]] ]
155 // CHECK-NEXT: ret void
157 void t92(void) {
158 // Check for proper type promotion of conditional expression
159 char c[(int)(sizeof(typeof((0 ? (_Complex double) 2.0f : 2.0f))) - sizeof(_Complex double))];
160 // Check for proper codegen
161 (0 ? (_Complex double) 2.0f : 2.0f);