1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=nsan -nsan-shadow-type-mapping=dqq -S %s | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5 ; Tests for invoke instructions that require special handling of the phis.
7 declare float @may_throw()
9 declare void @personalityFn()
11 define float @invoke1() sanitize_numerical_stability personality void ()* @personalityFn {
12 ; CHECK-LABEL: @invoke1(
14 ; CHECK-NEXT: [[C:%.*]] = invoke float @may_throw()
15 ; CHECK-NEXT: to label [[TMP0:%.*]] unwind label [[LAND:%.*]]
17 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr @__nsan_shadow_ret_tag, align 8
18 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], ptrtoint (ptr @may_throw to i64)
19 ; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr @__nsan_shadow_ret_ptr, align 8
20 ; CHECK-NEXT: [[TMP4:%.*]] = fpext float [[C]] to double
21 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], double [[TMP3]], double [[TMP4]]
22 ; CHECK-NEXT: br label [[CONTINUE:%.*]]
24 ; CHECK-NEXT: br label [[EXIT:%.*]]
26 ; CHECK-NEXT: [[RES:%.*]] = landingpad { ptr, i32 }
28 ; CHECK-NEXT: [[LV:%.*]] = uitofp i32 1 to float
29 ; CHECK-NEXT: br label [[EXIT]]
31 ; CHECK-NEXT: [[R:%.*]] = phi float [ [[LV]], [[LAND]] ], [ [[C]], [[CONTINUE]] ]
32 ; CHECK-NEXT: [[TMP6:%.*]] = phi double [ 1.000000e+00, [[LAND]] ], [ [[TMP5]], [[CONTINUE]] ]
33 ; CHECK-NEXT: [[TMP7:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP6]], i32 1, i64 0)
34 ; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[TMP7]], 1
35 ; CHECK-NEXT: [[TMP9:%.*]] = fpext float [[R]] to double
36 ; CHECK-NEXT: [[TMP10:%.*]] = select i1 [[TMP8]], double [[TMP9]], double [[TMP6]]
37 ; CHECK-NEXT: store i64 ptrtoint (ptr @invoke1 to i64), ptr @__nsan_shadow_ret_tag, align 8
38 ; CHECK-NEXT: store double [[TMP10]], ptr @__nsan_shadow_ret_ptr, align 8
39 ; CHECK-NEXT: ret float [[R]]
43 %c = invoke float @may_throw() to label %continue unwind label %land
49 %res = landingpad { ptr, i32 } cleanup
50 %lv = uitofp i32 1 to float
54 %r = phi float [ %lv, %land], [ %c, %continue ]
58 define float @invoke2() sanitize_numerical_stability personality void ()* @personalityFn {
59 ; CHECK-LABEL: @invoke2(
61 ; CHECK-NEXT: [[C:%.*]] = invoke float @may_throw()
62 ; CHECK-NEXT: to label [[TMP0:%.*]] unwind label [[LAND:%.*]]
64 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr @__nsan_shadow_ret_tag, align 8
65 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], ptrtoint (ptr @may_throw to i64)
66 ; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr @__nsan_shadow_ret_ptr, align 8
67 ; CHECK-NEXT: [[TMP4:%.*]] = fpext float [[C]] to double
68 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], double [[TMP3]], double [[TMP4]]
69 ; CHECK-NEXT: br label [[CONTINUE:%.*]]
71 ; CHECK-NEXT: [[CV:%.*]] = fadd float [[C]], 2.000000e+00
72 ; CHECK-NEXT: [[TMP6:%.*]] = fadd double [[TMP5]], 2.000000e+00
73 ; CHECK-NEXT: br label [[EXIT:%.*]]
75 ; CHECK-NEXT: [[RES:%.*]] = landingpad { ptr, i32 }
77 ; CHECK-NEXT: [[LV:%.*]] = uitofp i32 1 to float
78 ; CHECK-NEXT: br label [[EXIT]]
80 ; CHECK-NEXT: [[R:%.*]] = phi float [ [[LV]], [[LAND]] ], [ [[CV]], [[CONTINUE]] ]
81 ; CHECK-NEXT: [[TMP7:%.*]] = phi double [ 1.000000e+00, [[LAND]] ], [ [[TMP6]], [[CONTINUE]] ]
82 ; CHECK-NEXT: [[TMP8:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP7]], i32 1, i64 0)
83 ; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i32 [[TMP8]], 1
84 ; CHECK-NEXT: [[TMP10:%.*]] = fpext float [[R]] to double
85 ; CHECK-NEXT: [[TMP11:%.*]] = select i1 [[TMP9]], double [[TMP10]], double [[TMP7]]
86 ; CHECK-NEXT: store i64 ptrtoint (ptr @invoke2 to i64), ptr @__nsan_shadow_ret_tag, align 8
87 ; CHECK-NEXT: store double [[TMP11]], ptr @__nsan_shadow_ret_ptr, align 8
88 ; CHECK-NEXT: ret float [[R]]
92 %c = invoke float @may_throw() to label %continue unwind label %land
95 %cv = fadd float %c, 2.0
99 %res = landingpad { ptr, i32 } cleanup
100 %lv = uitofp i32 1 to float
104 %r = phi float [ %lv, %land], [ %cv, %continue ]
108 define float @invoke3() sanitize_numerical_stability personality void ()* @personalityFn {
109 ; CHECK-LABEL: @invoke3(
111 ; CHECK-NEXT: [[C:%.*]] = invoke float @may_throw()
112 ; CHECK-NEXT: to label [[TMP0:%.*]] unwind label [[LAND:%.*]]
114 ; CHECK-NEXT: [[RES:%.*]] = landingpad { ptr, i32 }
115 ; CHECK-NEXT: cleanup
116 ; CHECK-NEXT: [[LV:%.*]] = uitofp i32 1 to float
117 ; CHECK-NEXT: br label [[EXIT:%.*]]
119 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr @__nsan_shadow_ret_tag, align 8
120 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], ptrtoint (ptr @may_throw to i64)
121 ; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr @__nsan_shadow_ret_ptr, align 8
122 ; CHECK-NEXT: [[TMP4:%.*]] = fpext float [[C]] to double
123 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP2]], double [[TMP3]], double [[TMP4]]
124 ; CHECK-NEXT: br label [[EXIT]]
126 ; CHECK-NEXT: [[R:%.*]] = phi float [ [[LV]], [[LAND]] ], [ [[C]], [[TMP0]] ]
127 ; CHECK-NEXT: [[TMP6:%.*]] = phi double [ 1.000000e+00, [[LAND]] ], [ [[TMP5]], [[TMP0]] ]
128 ; CHECK-NEXT: [[TMP7:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP6]], i32 1, i64 0)
129 ; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i32 [[TMP7]], 1
130 ; CHECK-NEXT: [[TMP9:%.*]] = fpext float [[R]] to double
131 ; CHECK-NEXT: [[TMP10:%.*]] = select i1 [[TMP8]], double [[TMP9]], double [[TMP6]]
132 ; CHECK-NEXT: store i64 ptrtoint (ptr @invoke3 to i64), ptr @__nsan_shadow_ret_tag, align 8
133 ; CHECK-NEXT: store double [[TMP10]], ptr @__nsan_shadow_ret_ptr, align 8
134 ; CHECK-NEXT: ret float [[R]]
138 %c = invoke float @may_throw() to label %exit unwind label %land
141 %res = landingpad { ptr, i32 } cleanup
142 %lv = uitofp i32 1 to float
146 %r = phi float [ %lv, %land], [ %c, %entry ]