Home | History | Annotate | Download | only in CodeGen
      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 oge float %[[F:.*]], 0xC1E0000000000000
    289   // CHECK: %[[LE:.*]] = fcmp ole float %[[F]], 0x41DFFFFFE0000000
    290   // CHECK: and i1 %[[GE]], %[[LE]]
    291   // CHECK: call void @__ubsan_handle_float_cast_overflow(
    292 
    293   // CHECK-TRAP: %[[GE:.*]] = fcmp oge float %[[F:.*]], 0xC1E0000000000000
    294   // CHECK-TRAP: %[[LE:.*]] = fcmp ole float %[[F]], 0x41DFFFFFE0000000
    295   // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]]
    296   // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]]
    297 
    298   // CHECK-TRAP:      call void @llvm.trap() [[NR_NUW]]
    299   // CHECK-TRAP-NEXT: unreachable
    300   return f;
    301 }
    302 
    303 // CHECK: @float_uint_overflow
    304 // CHECK-TRAP: @float_uint_overflow
    305 unsigned float_uint_overflow(float f) {
    306   // CHECK: %[[GE:.*]] = fcmp oge float %[[F:.*]], 0.{{0*}}e+00
    307   // CHECK: %[[LE:.*]] = fcmp ole float %[[F]], 0x41EFFFFFE0000000
    308   // CHECK: and i1 %[[GE]], %[[LE]]
    309   // CHECK: call void @__ubsan_handle_float_cast_overflow(
    310 
    311   // CHECK-TRAP: %[[GE:.*]] = fcmp oge float %[[F:.*]], 0.{{0*}}e+00
    312   // CHECK-TRAP: %[[LE:.*]] = fcmp ole float %[[F]], 0x41EFFFFFE0000000
    313   // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]]
    314   // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]]
    315 
    316   // CHECK-TRAP:      call void @llvm.trap() [[NR_NUW]]
    317   // CHECK-TRAP-NEXT: unreachable
    318   return f;
    319 }
    320 
    321 // CHECK: @fp16_char_overflow
    322 // CHECK-TRAP: @fp16_char_overflow
    323 signed char fp16_char_overflow(__fp16 *p) {
    324   // CHECK: %[[GE:.*]] = fcmp oge float %[[F:.*]], -1.28{{0*}}e+02
    325   // CHECK: %[[LE:.*]] = fcmp ole float %[[F]], 1.27{{0*}}e+02
    326   // CHECK: and i1 %[[GE]], %[[LE]]
    327   // CHECK: call void @__ubsan_handle_float_cast_overflow(
    328 
    329   // CHECK-TRAP: %[[GE:.*]] = fcmp oge float %[[F:.*]], -1.28{{0*}}e+02
    330   // CHECK-TRAP: %[[LE:.*]] = fcmp ole float %[[F]], 1.27{{0*}}e+02
    331   // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]]
    332   // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]]
    333 
    334   // CHECK-TRAP:      call void @llvm.trap() [[NR_NUW]]
    335   // CHECK-TRAP-NEXT: unreachable
    336   return *p;
    337 }
    338 
    339 // CHECK: @float_float_overflow
    340 // CHECK-TRAP: @float_float_overflow
    341 float float_float_overflow(double f) {
    342   // CHECK: %[[GE:.*]] = fcmp oge double %[[F:.*]], 0xC7EFFFFFE0000000
    343   // CHECK: %[[LE:.*]] = fcmp ole double %[[F]], 0x47EFFFFFE0000000
    344   // CHECK: and i1 %[[GE]], %[[LE]]
    345   // CHECK: call void @__ubsan_handle_float_cast_overflow(
    346 
    347   // CHECK-TRAP: %[[GE:.*]] = fcmp oge double %[[F:.*]], 0xC7EFFFFFE0000000
    348   // CHECK-TRAP: %[[LE:.*]] = fcmp ole double %[[F]], 0x47EFFFFFE0000000
    349   // CHECK-TRAP: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]]
    350   // CHECK-TRAP-NEXT: br i1 %[[INBOUNDS]]
    351 
    352   // CHECK-TRAP:      call void @llvm.trap() [[NR_NUW]]
    353   // CHECK-TRAP-NEXT: unreachable
    354   return f;
    355 }
    356 
    357 // CHECK:          @int_divide_overflow
    358 // CHECK-OVERFLOW: @int_divide_overflow
    359 int int_divide_overflow(int a, int b) {
    360   // CHECK:               %[[ZERO:.*]] = icmp ne i32 %[[B:.*]], 0
    361   // CHECK-OVERFLOW-NOT:  icmp ne i32 %{{.*}}, 0
    362   // CHECK-TRAP:          %[[ZERO:.*]] = icmp ne i32 %[[B:.*]], 0
    363 
    364   // CHECK:               %[[AOK:.*]] = icmp ne i32 %[[A:.*]], -2147483648
    365   // CHECK-NEXT:          %[[BOK:.*]] = icmp ne i32 %[[B]], -1
    366   // CHECK-NEXT:          %[[OVER:.*]] = or i1 %[[AOK]], %[[BOK]]
    367 
    368   // CHECK-OVERFLOW:      %[[AOK:.*]] = icmp ne i32 %[[A:.*]], -2147483648
    369   // CHECK-OVERFLOW-NEXT: %[[BOK:.*]] = icmp ne i32 %[[B:.*]], -1
    370   // CHECK-OVERFLOW-NEXT: %[[OK:.*]] = or i1 %[[AOK]], %[[BOK]]
    371 
    372   // CHECK-TRAP:          %[[AOK:.*]] = icmp ne i32 %[[A:.*]], -2147483648
    373   // CHECK-TRAP-NEXT:     %[[BOK:.*]] = icmp ne i32 %[[B]], -1
    374   // CHECK-TRAP-NEXT:     %[[OVER:.*]] = or i1 %[[AOK]], %[[BOK]]
    375 
    376   // CHECK:               %[[OK:.*]] = and i1 %[[ZERO]], %[[OVER]]
    377 
    378   // CHECK:               br i1 %[[OK]]
    379   // CHECK-OVERFLOW:      br i1 %[[OK]]
    380 
    381   // CHECK-TRAP:          %[[OK:.*]] = and i1 %[[ZERO]], %[[OVER]]
    382   // CHECK-TRAP:          br i1 %[[OK]]
    383 
    384   // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]]
    385   // CHECK-TRAP: unreachable
    386   return a / b;
    387 
    388   // CHECK:          }
    389   // CHECK-OVERFLOW: }
    390   // CHECK-TRAP:     }
    391 }
    392 
    393 // CHECK: @sour_bool
    394 _Bool sour_bool(_Bool *p) {
    395   // CHECK: %[[OK:.*]] = icmp ule i8 {{.*}}, 1
    396   // CHECK: br i1 %[[OK]]
    397   // CHECK: call void @__ubsan_handle_load_invalid_value(i8* bitcast ({{.*}}), i64 {{.*}})
    398 
    399   // CHECK-TRAP: %[[OK:.*]] = icmp ule i8 {{.*}}, 1
    400   // CHECK-TRAP: br i1 %[[OK]]
    401 
    402   // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]]
    403   // CHECK-TRAP: unreachable
    404   return *p;
    405 }
    406 
    407 // CHECK: ![[WEIGHT_MD]] = metadata !{metadata !"branch_weights", i32 1048575, i32 1}
    408 
    409 // CHECK-TRAP: attributes [[NR_NUW]] = { noreturn nounwind }
    410