1 // RUN: %clang_cc1 -fsanitize=alignment,null,object-size,shift,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s 2 // RUN: %clang_cc1 -fsanitize-undefined-trap-on-error -fsanitize=alignment,null,object-size,shift,return,signed-integer-overflow,vla-bound,float-cast-overflow,integer-divide-by-zero,bool -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK-TRAP 3 // RUN: %clang_cc1 -fsanitize=null -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK-NULL 4 // RUN: %clang_cc1 -fsanitize=signed-integer-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK-OVERFLOW 5 6 // CHECK: @[[INT:.*]] = private unnamed_addr constant { i16, i16, [6 x i8] } { i16 0, i16 11, [6 x i8] c"'int'\00" } 7 8 // FIXME: When we only emit each type once, use [[INT]] more below. 9 // CHECK: @[[LINE_100:.*]] = private unnamed_addr global {{.*}}, i32 100, i32 5 {{.*}} @[[INT]], i64 4, i8 1 10 // CHECK: @[[LINE_200:.*]] = {{.*}}, i32 200, i32 10 {{.*}}, i64 4, i8 0 11 // CHECK: @[[LINE_300:.*]] = {{.*}}, i32 300, i32 12 {{.*}} @{{.*}}, {{.*}} @{{.*}} 12 // CHECK: @[[LINE_400:.*]] = {{.*}}, i32 400, i32 12 {{.*}} @{{.*}}, {{.*}} @{{.*}} 13 // CHECK: @[[LINE_500:.*]] = {{.*}}, i32 500, i32 10 {{.*}} @{{.*}}, i64 4, i8 0 } 14 // CHECK: @[[LINE_600:.*]] = {{.*}}, i32 600, i32 3 {{.*}} @{{.*}}, i64 4, i8 1 } 15 16 // CHECK: @[[STRUCT_S:.*]] = private unnamed_addr constant { i16, i16, [11 x i8] } { i16 -1, i16 0, [11 x i8] c"'struct S'\00" } 17 18 // CHECK: @[[LINE_700:.*]] = {{.*}}, i32 700, i32 14 {{.*}} @[[STRUCT_S]], i64 4, i8 3 } 19 // CHECK: @[[LINE_800:.*]] = {{.*}}, i32 800, i32 12 {{.*}} @{{.*}} } 20 // CHECK: @[[LINE_900:.*]] = {{.*}}, i32 900, i32 11 {{.*}} @{{.*}} } 21 22 // CHECK-NULL: @[[LINE_100:.*]] = private unnamed_addr global {{.*}}, i32 100, i32 5 {{.*}} 23 24 // PR6805 25 // CHECK: @foo 26 // CHECK-NULL: @foo 27 // CHECK-TRAP: @foo 28 void foo() { 29 union { int i; } u; 30 // CHECK: %[[CHECK0:.*]] = icmp ne {{.*}}* %[[PTR:.*]], null 31 // CHECK-TRAP: %[[CHECK0:.*]] = icmp ne {{.*}}* %[[PTR:.*]], null 32 33 // CHECK: %[[I8PTR:.*]] = bitcast i32* %[[PTR]] to i8* 34 // CHECK-NEXT: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64(i8* %[[I8PTR]], i1 false) 35 // CHECK-NEXT: %[[CHECK1:.*]] = icmp uge i64 %[[SIZE]], 4 36 // CHECK-NEXT: %[[CHECK01:.*]] = and i1 %[[CHECK0]], %[[CHECK1]] 37 38 // CHECK-TRAP: %[[I8PTR:.*]] = bitcast i32* %[[PTR]] to i8* 39 // CHECK-TRAP-NEXT: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64(i8* %[[I8PTR]], i1 false) 40 // CHECK-TRAP-NEXT: %[[CHECK1:.*]] = icmp uge i64 %[[SIZE]], 4 41 // CHECK-TRAP-NEXT: %[[CHECK01:.*]] = and i1 %[[CHECK0]], %[[CHECK1]] 42 43 // CHECK: %[[PTRTOINT:.*]] = ptrtoint {{.*}}* %[[PTR]] to i64 44 // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRTOINT]], 3 45 // CHECK-NEXT: %[[CHECK2:.*]] = icmp eq i64 %[[MISALIGN]], 0 46 47 // CHECK-TRAP: %[[PTRTOINT:.*]] = ptrtoint {{.*}}* %[[PTR]] to i64 48 // CHECK-TRAP-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRTOINT]], 3 49 // CHECK-TRAP-NEXT: %[[CHECK2:.*]] = icmp eq i64 %[[MISALIGN]], 0 50 51 // CHECK: %[[OK:.*]] = and i1 %[[CHECK01]], %[[CHECK2]] 52 // CHECK-NEXT: br i1 %[[OK]], {{.*}} !prof ![[WEIGHT_MD:.*]] 53 54 // CHECK-TRAP: %[[OK:.*]] = and i1 %[[CHECK01]], %[[CHECK2]] 55 // CHECK-TRAP-NEXT: br i1 %[[OK]], {{.*}} 56 57 // CHECK: %[[ARG:.*]] = ptrtoint {{.*}} %[[PTR]] to i64 58 // CHECK-NEXT: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_100]] to i8*), i64 %[[ARG]]) 59 60 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW:#[0-9]+]] 61 // CHECK-TRAP-NEXT: unreachable 62 63 // With -fsanitize=null, only perform the null check. 64 // CHECK-NULL: %[[NULL:.*]] = icmp ne {{.*}}, null 65 // CHECK-NULL: br i1 %[[NULL]] 66 // CHECK-NULL: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_100]] to i8*), i64 %{{.*}}) 67 #line 100 68 u.i=1; 69 } 70 71 // CHECK: @bar 72 // CHECK-TRAP: @bar 73 int bar(int *a) { 74 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64 75 // CHECK-NEXT: icmp uge i64 %[[SIZE]], 4 76 77 // CHECK-TRAP: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64 78 // CHECK-TRAP-NEXT: icmp uge i64 %[[SIZE]], 4 79 80 // CHECK: %[[PTRINT:.*]] = ptrtoint 81 // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3 82 // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0 83 84 // CHECK-TRAP: %[[PTRINT:.*]] = ptrtoint 85 // CHECK-TRAP-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3 86 // CHECK-TRAP-NEXT: icmp eq i64 %[[MISALIGN]], 0 87 88 // CHECK: %[[ARG:.*]] = ptrtoint 89 // CHECK-NEXT: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_200]] to i8*), i64 %[[ARG]]) 90 91 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 92 // CHECK-TRAP-NEXT: unreachable 93 94 #line 200 95 return *a; 96 } 97 98 // CHECK: @addr_space 99 int addr_space(int __attribute__((address_space(256))) *a) { 100 // CHECK-NOT: __ubsan 101 return *a; 102 } 103 104 // CHECK: @lsh_overflow 105 // CHECK-TRAP: @lsh_overflow 106 int lsh_overflow(int a, int b) { 107 // CHECK: %[[INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31 108 // CHECK-NEXT: br i1 %[[INBOUNDS]], label %[[CHECKBB:.*]], label %[[CONTBB:.*]] 109 110 // CHECK-TRAP: %[[INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31 111 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]], label %[[CHECKBB:.*]], label %[[CONTBB:.*]] 112 113 // CHECK: %[[SHIFTED_OUT_WIDTH:.*]] = sub nuw nsw i32 31, %[[RHS]] 114 // CHECK-NEXT: %[[SHIFTED_OUT:.*]] = lshr i32 %[[LHS:.*]], %[[SHIFTED_OUT_WIDTH]] 115 // CHECK-NEXT: %[[NO_OVERFLOW:.*]] = icmp eq i32 %[[SHIFTED_OUT]], 0 116 // CHECK-NEXT: br label %[[CONTBB]] 117 118 // CHECK-TRAP: %[[SHIFTED_OUT_WIDTH:.*]] = sub nuw nsw i32 31, %[[RHS]] 119 // CHECK-TRAP-NEXT: %[[SHIFTED_OUT:.*]] = lshr i32 %[[LHS:.*]], %[[SHIFTED_OUT_WIDTH]] 120 // CHECK-TRAP-NEXT: %[[NO_OVERFLOW:.*]] = icmp eq i32 %[[SHIFTED_OUT]], 0 121 // CHECK-TRAP-NEXT: br label %[[CONTBB]] 122 123 // CHECK: %[[VALID:.*]] = phi i1 [ %[[INBOUNDS]], {{.*}} ], [ %[[NO_OVERFLOW]], %[[CHECKBB]] ] 124 // CHECK-NEXT: br i1 %[[VALID]], {{.*}} !prof ![[WEIGHT_MD]] 125 126 // CHECK-TRAP: %[[VALID:.*]] = phi i1 [ %[[INBOUNDS]], {{.*}} ], [ %[[NO_OVERFLOW]], %[[CHECKBB]] ] 127 // CHECK-TRAP-NEXT: br i1 %[[VALID]] 128 129 130 // CHECK: %[[ARG1:.*]] = zext 131 // CHECK-NEXT: %[[ARG2:.*]] = zext 132 // CHECK-NEXT: call void @__ubsan_handle_shift_out_of_bounds(i8* bitcast ({{.*}} @[[LINE_300]] to i8*), i64 %[[ARG1]], i64 %[[ARG2]]) 133 // CHECK-NOT: call void @__ubsan_handle_shift_out_of_bounds 134 135 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 136 // CHECK-TRAP: unreachable 137 // CHECK-TRAP-NOT: call void @llvm.trap() 138 139 // CHECK: %[[RET:.*]] = shl i32 %[[LHS]], %[[RHS]] 140 // CHECK-NEXT: ret i32 %[[RET]] 141 142 // CHECK-TRAP: %[[RET:.*]] = shl i32 %[[LHS]], %[[RHS]] 143 // CHECK-TRAP-NEXT: ret i32 %[[RET]] 144 #line 300 145 return a << b; 146 } 147 148 // CHECK: @rsh_inbounds 149 // CHECK-TRAP: @rsh_inbounds 150 int rsh_inbounds(int a, int b) { 151 // CHECK: %[[INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31 152 // CHECK: br i1 %[[INBOUNDS]] 153 154 // CHECK-TRAP: %[[INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31 155 // CHECK-TRAP: br i1 %[[INBOUNDS]] 156 157 // CHECK: %[[ARG1:.*]] = zext 158 // CHECK-NEXT: %[[ARG2:.*]] = zext 159 // CHECK-NEXT: call void @__ubsan_handle_shift_out_of_bounds(i8* bitcast ({{.*}} @[[LINE_400]] to i8*), i64 %[[ARG1]], i64 %[[ARG2]]) 160 161 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 162 // CHECK-TRAP-NEXT: unreachable 163 164 // CHECK: %[[RET:.*]] = ashr i32 %[[LHS]], %[[RHS]] 165 // CHECK-NEXT: ret i32 %[[RET]] 166 167 // CHECK-TRAP: %[[RET:.*]] = ashr i32 %[[LHS]], %[[RHS]] 168 // CHECK-TRAP-NEXT: ret i32 %[[RET]] 169 #line 400 170 return a >> b; 171 } 172 173 // CHECK: @load 174 // CHECK-TRAP: @load 175 int load(int *p) { 176 // CHECK: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_500]] to i8*), i64 %{{.*}}) 177 178 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 179 // CHECK-TRAP-NEXT: unreachable 180 #line 500 181 return *p; 182 } 183 184 // CHECK: @store 185 // CHECK-TRAP: @store 186 void store(int *p, int q) { 187 // CHECK: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_600]] to i8*), i64 %{{.*}}) 188 189 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 190 // CHECK-TRAP-NEXT: unreachable 191 #line 600 192 *p = q; 193 } 194 195 struct S { int k; }; 196 197 // CHECK: @member_access 198 // CHECK-TRAP: @member_access 199 int *member_access(struct S *p) { 200 // CHECK: call void @__ubsan_handle_type_mismatch(i8* bitcast ({{.*}} @[[LINE_700]] to i8*), i64 %{{.*}}) 201 202 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 203 // CHECK-TRAP-NEXT: unreachable 204 #line 700 205 return &p->k; 206 } 207 208 // CHECK: @signed_overflow 209 // CHECK-TRAP: @signed_overflow 210 int signed_overflow(int a, int b) { 211 // CHECK: %[[ARG1:.*]] = zext 212 // CHECK-NEXT: %[[ARG2:.*]] = zext 213 // CHECK-NEXT: call void @__ubsan_handle_add_overflow(i8* bitcast ({{.*}} @[[LINE_800]] to i8*), i64 %[[ARG1]], i64 %[[ARG2]]) 214 215 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 216 // CHECK-TRAP-NEXT: unreachable 217 #line 800 218 return a + b; 219 } 220 221 // CHECK: @no_return 222 // CHECK-TRAP: @no_return 223 int no_return() { 224 // Reaching the end of a noreturn function is fine in C. 225 // FIXME: If the user explicitly requests -fsanitize=return, we should catch 226 // that here even though it's not undefined behavior. 227 // CHECK-NOT: call 228 // CHECK-NOT: unreachable 229 // CHECK: ret i32 230 231 // CHECK-TRAP-NOT: call 232 // CHECK-TRAP-NOT: unreachable 233 // CHECK-TRAP: ret i32 234 } 235 236 // CHECK: @vla_bound 237 void vla_bound(int n) { 238 // CHECK: icmp sgt i32 %[[PARAM:.*]], 0 239 // 240 // CHECK: %[[ARG:.*]] = zext i32 %[[PARAM]] to i64 241 // CHECK-NEXT: call void @__ubsan_handle_vla_bound_not_positive(i8* bitcast ({{.*}} @[[LINE_900]] to i8*), i64 %[[ARG]]) 242 #line 900 243 int arr[n * 3]; 244 } 245 246 // CHECK: @int_float_no_overflow 247 float int_float_no_overflow(__int128 n) { 248 // CHECK-NOT: call void @__ubsan_handle 249 return n; 250 } 251 252 // CHECK: @int_float_overflow 253 // CHECK-TRAP: @int_float_overflow 254 float int_float_overflow(unsigned __int128 n) { 255 // This is 2**104. FLT_MAX is 2**128 - 2**104. 256 // CHECK: icmp ule i128 %{{.*}}, -20282409603651670423947251286016 257 // CHECK: call void @__ubsan_handle_float_cast_overflow( 258 259 // CHECK-TRAP: %[[INBOUNDS:.*]] = icmp ule i128 %{{.*}}, -20282409603651670423947251286016 260 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]] 261 262 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 263 // CHECK-TRAP-NEXT: unreachable 264 return n; 265 } 266 267 // CHECK: @int_fp16_overflow 268 // CHECK-TRAP: @int_fp16_overflow 269 void int_fp16_overflow(int n, __fp16 *p) { 270 // CHECK: %[[GE:.*]] = icmp sge i32 %{{.*}}, -65504 271 // CHECK: %[[LE:.*]] = icmp sle i32 %{{.*}}, 65504 272 // CHECK: and i1 %[[GE]], %[[LE]] 273 // CHECK: call void @__ubsan_handle_float_cast_overflow( 274 275 // CHECK-TRAP: %[[GE:.*]] = icmp sge i32 %{{.*}}, -65504 276 // CHECK-TRAP: %[[LE:.*]] = icmp sle i32 %{{.*}}, 65504 277 // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] 278 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]] 279 280 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 281 // CHECK-TRAP-NEXT: unreachable 282 *p = n; 283 } 284 285 // CHECK: @float_int_overflow 286 // CHECK-TRAP: @float_int_overflow 287 int float_int_overflow(float f) { 288 // CHECK: %[[GE:.*]] = fcmp ogt float %[[F:.*]], 0xC1E0000020000000 289 // CHECK: %[[LE:.*]] = fcmp olt float %[[F]], 0x41E0000000000000 290 // CHECK: and i1 %[[GE]], %[[LE]] 291 292 // CHECK: %[[CAST:.*]] = bitcast float %[[F]] to i32 293 // CHECK: %[[ARG:.*]] = zext i32 %[[CAST]] to i64 294 // CHECK: call void @__ubsan_handle_float_cast_overflow({{.*}}, i64 %[[ARG]] 295 296 // CHECK-TRAP: %[[GE:.*]] = fcmp ogt float %[[F:.*]], 0xC1E0000020000000 297 // CHECK-TRAP: %[[LE:.*]] = fcmp olt float %[[F]], 0x41E0000000000000 298 // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] 299 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]] 300 301 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 302 // CHECK-TRAP-NEXT: unreachable 303 return f; 304 } 305 306 // CHECK: @long_double_int_overflow 307 // CHECK-TRAP: @long_double_int_overflow 308 int long_double_int_overflow(long double ld) { 309 // CHECK: alloca x86_fp80 310 // CHECK: %[[GE:.*]] = fcmp ogt x86_fp80 %[[F:.*]], 0xKC01E8000000100000000 311 // CHECK: %[[LE:.*]] = fcmp olt x86_fp80 %[[F]], 0xK401E8000000000000000 312 // CHECK: and i1 %[[GE]], %[[LE]] 313 314 // CHECK: store x86_fp80 %[[F]], x86_fp80* %[[ALLOCA:.*]] 315 // CHECK: %[[ARG:.*]] = ptrtoint x86_fp80* %[[ALLOCA]] to i64 316 // CHECK: call void @__ubsan_handle_float_cast_overflow({{.*}}, i64 %[[ARG]] 317 318 // CHECK-TRAP: %[[GE:.*]] = fcmp ogt x86_fp80 %[[F:.*]], 0xKC01E800000010000000 319 // CHECK-TRAP: %[[LE:.*]] = fcmp olt x86_fp80 %[[F]], 0xK401E800000000000000 320 // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] 321 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]] 322 323 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 324 // CHECK-TRAP-NEXT: unreachable 325 return ld; 326 } 327 328 // CHECK: @float_uint_overflow 329 // CHECK-TRAP: @float_uint_overflow 330 unsigned float_uint_overflow(float f) { 331 // CHECK: %[[GE:.*]] = fcmp ogt float %[[F:.*]], -1.{{0*}}e+00 332 // CHECK: %[[LE:.*]] = fcmp olt float %[[F]], 0x41F0000000000000 333 // CHECK: and i1 %[[GE]], %[[LE]] 334 // CHECK: call void @__ubsan_handle_float_cast_overflow( 335 336 // CHECK-TRAP: %[[GE:.*]] = fcmp ogt float %[[F:.*]], -1.{{0*}}e+00 337 // CHECK-TRAP: %[[LE:.*]] = fcmp olt float %[[F]], 0x41F0000000000000 338 // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] 339 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]] 340 341 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 342 // CHECK-TRAP-NEXT: unreachable 343 return f; 344 } 345 346 // CHECK: @fp16_char_overflow 347 // CHECK-TRAP: @fp16_char_overflow 348 signed char fp16_char_overflow(__fp16 *p) { 349 // CHECK: %[[GE:.*]] = fcmp ogt float %[[F:.*]], -1.29{{0*}}e+02 350 // CHECK: %[[LE:.*]] = fcmp olt float %[[F]], 1.28{{0*}}e+02 351 // CHECK: and i1 %[[GE]], %[[LE]] 352 // CHECK: call void @__ubsan_handle_float_cast_overflow( 353 354 // CHECK-TRAP: %[[GE:.*]] = fcmp ogt float %[[F:.*]], -1.29{{0*}}e+02 355 // CHECK-TRAP: %[[LE:.*]] = fcmp olt float %[[F]], 1.28{{0*}}e+02 356 // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] 357 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]] 358 359 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 360 // CHECK-TRAP-NEXT: unreachable 361 return *p; 362 } 363 364 // CHECK: @float_float_overflow 365 // CHECK-TRAP: @float_float_overflow 366 float float_float_overflow(double f) { 367 // CHECK: %[[F:.*]] = call double @llvm.fabs.f64( 368 // CHECK: %[[GE:.*]] = fcmp ogt double %[[F]], 0x47EFFFFFE0000000 369 // CHECK: %[[LE:.*]] = fcmp olt double %[[F]], 0x7FF0000000000000 370 // CHECK: and i1 %[[GE]], %[[LE]] 371 // CHECK: call void @__ubsan_handle_float_cast_overflow( 372 373 // CHECK-TRAP: %[[F:.*]] = call double @llvm.fabs.f64( 374 // CHECK-TRAP: %[[GE:.*]] = fcmp ogt double %[[F]], 0x47EFFFFFE0000000 375 // CHECK-TRAP: %[[LE:.*]] = fcmp olt double %[[F]], 0x7FF0000000000000 376 // CHECK-TRAP: %[[OUTOFBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] 377 // CHECK-TRAP: %[[INBOUNDS:.*]] = xor i1 %[[OUTOFBOUNDS]], true 378 // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]] 379 380 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 381 // CHECK-TRAP-NEXT: unreachable 382 return f; 383 } 384 385 // CHECK: @int_divide_overflow 386 // CHECK-OVERFLOW: @int_divide_overflow 387 int int_divide_overflow(int a, int b) { 388 // CHECK: %[[ZERO:.*]] = icmp ne i32 %[[B:.*]], 0 389 // CHECK-OVERFLOW-NOT: icmp ne i32 %{{.*}}, 0 390 // CHECK-TRAP: %[[ZERO:.*]] = icmp ne i32 %[[B:.*]], 0 391 392 // CHECK: %[[AOK:.*]] = icmp ne i32 %[[A:.*]], -2147483648 393 // CHECK-NEXT: %[[BOK:.*]] = icmp ne i32 %[[B]], -1 394 // CHECK-NEXT: %[[OVER:.*]] = or i1 %[[AOK]], %[[BOK]] 395 396 // CHECK-OVERFLOW: %[[AOK:.*]] = icmp ne i32 %[[A:.*]], -2147483648 397 // CHECK-OVERFLOW-NEXT: %[[BOK:.*]] = icmp ne i32 %[[B:.*]], -1 398 // CHECK-OVERFLOW-NEXT: %[[OK:.*]] = or i1 %[[AOK]], %[[BOK]] 399 400 // CHECK-TRAP: %[[AOK:.*]] = icmp ne i32 %[[A:.*]], -2147483648 401 // CHECK-TRAP-NEXT: %[[BOK:.*]] = icmp ne i32 %[[B]], -1 402 // CHECK-TRAP-NEXT: %[[OVER:.*]] = or i1 %[[AOK]], %[[BOK]] 403 404 // CHECK: %[[OK:.*]] = and i1 %[[ZERO]], %[[OVER]] 405 406 // CHECK: br i1 %[[OK]] 407 // CHECK-OVERFLOW: br i1 %[[OK]] 408 409 // CHECK-TRAP: %[[OK:.*]] = and i1 %[[ZERO]], %[[OVER]] 410 // CHECK-TRAP: br i1 %[[OK]] 411 412 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 413 // CHECK-TRAP: unreachable 414 return a / b; 415 416 // CHECK: } 417 // CHECK-OVERFLOW: } 418 // CHECK-TRAP: } 419 } 420 421 // CHECK: @sour_bool 422 _Bool sour_bool(_Bool *p) { 423 // CHECK: %[[OK:.*]] = icmp ule i8 {{.*}}, 1 424 // CHECK: br i1 %[[OK]] 425 // CHECK: call void @__ubsan_handle_load_invalid_value(i8* bitcast ({{.*}}), i64 {{.*}}) 426 427 // CHECK-TRAP: %[[OK:.*]] = icmp ule i8 {{.*}}, 1 428 // CHECK-TRAP: br i1 %[[OK]] 429 430 // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] 431 // CHECK-TRAP: unreachable 432 return *p; 433 } 434 435 // CHECK: ![[WEIGHT_MD]] = metadata !{metadata !"branch_weights", i32 1048575, i32 1} 436 437 // CHECK-TRAP: attributes [[NR_NUW]] = { noreturn nounwind } 438