&& "Unsupported builtin check kind");
Value *ArgValue = EmitScalarExpr(E);
- if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef())
+ if (!SanOpts.has(SanitizerKind::Builtin))
return ArgValue;
SanitizerScope SanScope(this);
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefix=NOT-UB
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,POISON
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,NOPOISON
-// NOT-UB-NOT: __ubsan_handle_invalid_builtin
+// A zero input to __bultin_ctz/clz is considered UB even if the target does not
+// want to optimize based on zero input being undefined.
// CHECK: define{{.*}} void @check_ctz
void check_ctz(int n) {
// CHECK-NEXT: unreachable
//
// Continuation block:
- // CHECK: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+ // POISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+ // NOPOISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 false)
__builtin_ctz(n);
// CHECK: call void @__ubsan_handle_invalid_builtin
// CHECK-NEXT: unreachable
//
// Continuation block:
- // CHECK: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+ // POISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+ // NOPOISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 false)
__builtin_clz(n);
// CHECK: call void @__ubsan_handle_invalid_builtin