1 // RUN: %clang_cc1 -fcatch-undefined-behavior -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s 2 3 // PR6805 4 // CHECK: @foo 5 void foo() { 6 union { int i; } u; 7 // CHECK: objectsize 8 // CHECK: icmp uge 9 u.i=1; 10 } 11 12 // CHECK: @bar 13 int bar(int *a) { 14 // CHECK: %[[SIZE:.*]] = call i64 @llvm.objectsize.i64 15 // CHECK-NEXT: icmp uge i64 %[[SIZE]], 4 16 17 // CHECK: %[[PTRINT:.*]] = ptrtoint 18 // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3 19 // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0 20 return *a; 21 } 22 23 // CHECK: @lsh_overflow 24 int lsh_overflow(int a, int b) { 25 // CHECK: %[[INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31 26 // CHECK-NEXT: br i1 %[[INBOUNDS]] 27 28 // CHECK: %[[SHIFTED_OUT_WIDTH:.*]] = sub nuw nsw i32 31, %[[RHS]] 29 // CHECK-NEXT: %[[SHIFTED_OUT:.*]] = lshr i32 %[[LHS:.*]], %[[SHIFTED_OUT_WIDTH]] 30 // CHECK-NEXT: %[[NO_OVERFLOW:.*]] = icmp eq i32 %[[SHIFTED_OUT]], 0 31 // CHECK-NEXT: br i1 %[[NO_OVERFLOW]] 32 33 // CHECK: %[[RET:.*]] = shl i32 %[[LHS]], %[[RHS]] 34 // CHECK-NEXT: ret i32 %[[RET]] 35 return a << b; 36 } 37 38 // CHECK: @rsh_inbounds 39 int rsh_inbounds(int a, int b) { 40 // CHECK: %[[INBOUNDS:.*]] = icmp ult i32 %[[RHS:.*]], 32 41 // CHECK: br i1 %[[INBOUNDS]] 42 43 // CHECK: %[[RET:.*]] = ashr i32 %[[LHS]], %[[RHS]] 44 // CHECK-NEXT: ret i32 %[[RET]] 45 return a >> b; 46 } 47