From 461a67fa15370a9ec88f8f8a240bf7c123bb2029 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 18 Dec 2017 20:11:37 +0000 Subject: Vendor import of clang trunk r321017: https://llvm.org/svn/llvm-project/cfe/trunk@321017 --- test/CodeGen/ubsan-builtin-checks.c | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/CodeGen/ubsan-builtin-checks.c (limited to 'test/CodeGen/ubsan-builtin-checks.c') diff --git a/test/CodeGen/ubsan-builtin-checks.c b/test/CodeGen/ubsan-builtin-checks.c new file mode 100644 index 000000000000..9733b0e04794 --- /dev/null +++ b/test/CodeGen/ubsan-builtin-checks.c @@ -0,0 +1,44 @@ +// 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 + +// NOT-UB-NOT: __ubsan_handle_invalid_builtin + +// CHECK: define void @check_ctz +void check_ctz(int n) { + // CHECK: [[NOT_ZERO:%.*]] = icmp ne i32 [[N:%.*]], 0, !nosanitize + // CHECK-NEXT: br i1 [[NOT_ZERO]] + // + // Handler block: + // CHECK: call void @__ubsan_handle_invalid_builtin + // CHECK-NEXT: unreachable + // + // Continuation block: + // CHECK: call i32 @llvm.cttz.i32(i32 [[N]], i1 true) + __builtin_ctz(n); + + // CHECK: call void @__ubsan_handle_invalid_builtin + __builtin_ctzl(n); + + // CHECK: call void @__ubsan_handle_invalid_builtin + __builtin_ctzll(n); +} + +// CHECK: define void @check_clz +void check_clz(int n) { + // CHECK: [[NOT_ZERO:%.*]] = icmp ne i32 [[N:%.*]], 0, !nosanitize + // CHECK-NEXT: br i1 [[NOT_ZERO]] + // + // Handler block: + // CHECK: call void @__ubsan_handle_invalid_builtin + // CHECK-NEXT: unreachable + // + // Continuation block: + // CHECK: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true) + __builtin_clz(n); + + // CHECK: call void @__ubsan_handle_invalid_builtin + __builtin_clzl(n); + + // CHECK: call void @__ubsan_handle_invalid_builtin + __builtin_clzll(n); +} -- cgit v1.2.3