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]]
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)
21 // CHECK: call void @__ubsan_handle_invalid_builtin
24 // CHECK: call void @__ubsan_handle_invalid_builtin
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]]
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)
42 // CHECK: call void @__ubsan_handle_invalid_builtin
45 // CHECK: call void @__ubsan_handle_invalid_builtin