Skip to content

Commit 4914d33

Browse files
committed
-fsanitize=function: Add a (bugged) test case for a sugared function type
1 parent 2ed0453 commit 4914d33

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,GNU,64
2+
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,MSVC,64
3+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,GNU,64
4+
// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,GNU,64
5+
// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,ARM,GNU,32
6+
7+
// GNU: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
8+
// MSVC: define{{.*}} void @"?fun@@YA?A?<auto>@@XZ"() #0 !func_sanitize ![[FUNCSAN:.*]] {
9+
auto fun() {}
10+
11+
// GNU-LABEL: define{{.*}} void @_Z6callerv()
12+
// MSVC-LABEL: define{{.*}} void @"?caller@@YAXXZ"()
13+
// ARM: ptrtoint ptr {{.*}} to i32, !nosanitize !4
14+
// ARM: and i32 {{.*}}, -2, !nosanitize !4
15+
// ARM: inttoptr i32 {{.*}} to ptr, !nosanitize !4
16+
// CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
17+
// CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
18+
// CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
19+
// CHECK: br i1 {{.*}}, label %[[LABEL1:.*]], label %[[LABEL4:.*]], !nosanitize
20+
// CHECK: [[LABEL1]]:
21+
// CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 1, !nosanitize
22+
// CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
23+
// GNU: icmp eq i32 {{.*}}, 905068220, !nosanitize
24+
// MSVC: icmp eq i32 {{.*}}, -1600339357, !nosanitize
25+
// CHECK: br i1 {{.*}}, label %[[LABEL3:.*]], label %[[LABEL2:[^,]*]], {{.*}}!nosanitize
26+
// CHECK: [[LABEL2]]:
27+
// 64: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], i64 %[[#]]) #[[#]], !nosanitize
28+
// 32: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], i32 %[[#]]) #[[#]], !nosanitize
29+
// CHECK-NEXT: unreachable, !nosanitize
30+
// CHECK-EMPTY:
31+
// CHECK-NEXT: [[LABEL3]]:
32+
// CHECK: br label %[[LABEL4]], !nosanitize
33+
// CHECK-EMPTY:
34+
// CHECK-NEXT: [[LABEL4]]:
35+
// CHECK-NEXT: call void
36+
// CHECK-NEXT: ret void
37+
void caller() {
38+
auto a = fun;
39+
a();
40+
}
41+
42+
// GNU: ![[FUNCSAN]] = !{i32 -1056584962, i32 905068220}
43+
// FIXME: Wrong hash
44+
// MSVC: ![[FUNCSAN]] = !{i32 -1056584962, i32 165986058}

0 commit comments

Comments
 (0)