[Flang] remove whole-archive option for AIX linker (#76039)
[llvm-project.git] / clang / test / CodeGen / bounds-checking.c
blob636d4f289e247863f1f312c57e03792f1d99f616
1 // RUN: %clang_cc1 -fsanitize=local-bounds -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-trap=array-bounds -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - | FileCheck %s
3 // RUN: %clang_cc1 -fsanitize=local-bounds -fsanitize-trap=local-bounds -O3 -mllvm -bounds-checking-unique-traps -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTLOCAL
4 // RUN: %clang_cc1 -fsanitize=array-bounds -fsanitize-trap=array-bounds -O3 -mllvm -ubsan-unique-traps -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTARRAY
5 //
6 // REQUIRES: x86-registered-target
8 // CHECK-LABEL: @f1
9 double f1(int b, int i) {
10 double a[b];
11 // CHECK: call {{.*}} @llvm.{{(ubsan)?trap}}
12 return a[i];
15 // CHECK-LABEL: @f2
16 void f2(void) {
17 // everything is constant; no trap possible
18 // CHECK-NOT: call {{.*}} @llvm.{{(ubsan)?trap}}
19 int a[2];
20 a[1] = 42;
22 #ifndef NO_DYNAMIC
23 extern void *malloc(__typeof__(sizeof(0)));
24 short *b = malloc(64);
25 b[5] = *a + a[1] + 2;
26 #endif
29 // CHECK-LABEL: @f3
30 void f3(void) {
31 int a[1];
32 // CHECK: call {{.*}} @llvm.{{(ubsan)?trap}}
33 a[2] = 1;
36 // CHECK-LABEL: @f4
37 __attribute__((no_sanitize("bounds")))
38 int f4(int i) {
39 int b[64];
40 // CHECK-NOT: call void @llvm.trap()
41 // CHECK-NOT: trap:
42 // CHECK-NOT: cont:
43 return b[i];
46 // Union flexible-array memebers are a C99 extension. All array members with a
47 // constant size should be considered FAMs.
49 union U { int a[0]; int b[1]; int c[2]; };
51 // CHECK-LABEL: @f5
52 int f5(union U *u, int i) {
53 // a is treated as a flexible array member.
54 // CHECK-NOT: @llvm.ubsantrap
55 return u->a[i];
58 // CHECK-LABEL: @f6
59 int f6(union U *u, int i) {
60 // b is treated as a flexible array member.
61 // CHECK-NOT: call {{.*}} @llvm.{{(ubsan)?trap}}
62 return u->b[i];
65 // CHECK-LABEL: @f7
66 int f7(union U *u, int i) {
67 // c is treated as a flexible array member.
68 // CHECK-NOT: @llvm.ubsantrap
69 return u->c[i];
73 char B[10];
74 char B2[10];
75 // CHECK-LABEL: @f8
76 void f8(int i, int k) {
77 // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3)
78 // NOOPTARRAY: call void @llvm.ubsantrap(i8 2)
79 B[i] = '\0';
81 // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5)
82 // NOOPTARRAY: call void @llvm.ubsantrap(i8 4)
83 B2[k] = '\0';