Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / ubsan-builtin-checks.c
blob2bc32d8df4850d5fe0dbdc3188cecbc96673e008
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,POISON
2 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,NOPOISON
4 // A zero input to __bultin_ctz/clz is considered UB even if the target does not
5 // want to optimize based on zero input being undefined.
7 // CHECK: define{{.*}} void @check_ctz
8 void check_ctz(int n) {
9 // CHECK: [[NOT_ZERO:%.*]] = icmp ne i32 [[N:%.*]], 0, !nosanitize
10 // CHECK-NEXT: br i1 [[NOT_ZERO]]
12 // Handler block:
13 // CHECK: call void @__ubsan_handle_invalid_builtin
14 // CHECK-NEXT: unreachable
16 // Continuation block:
17 // POISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
18 // NOPOISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 false)
19 __builtin_ctz(n);
21 // CHECK: call void @__ubsan_handle_invalid_builtin
22 __builtin_ctzl(n);
24 // CHECK: call void @__ubsan_handle_invalid_builtin
25 __builtin_ctzll(n);
28 // CHECK: define{{.*}} void @check_clz
29 void check_clz(int n) {
30 // CHECK: [[NOT_ZERO:%.*]] = icmp ne i32 [[N:%.*]], 0, !nosanitize
31 // CHECK-NEXT: br i1 [[NOT_ZERO]]
33 // Handler block:
34 // CHECK: call void @__ubsan_handle_invalid_builtin
35 // CHECK-NEXT: unreachable
37 // Continuation block:
38 // POISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
39 // NOPOISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 false)
40 __builtin_clz(n);
42 // CHECK: call void @__ubsan_handle_invalid_builtin
43 __builtin_clzl(n);
45 // CHECK: call void @__ubsan_handle_invalid_builtin
46 __builtin_clzll(n);