comparison clang/test/CodeGen/nonnull.c @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -check-prefix=NULL-INVALID %s 1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -check-prefix=NULL-INVALID %s
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -fno-delete-null-pointer-checks < %s | FileCheck -check-prefix=NULL-VALID %s 2 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -fno-delete-null-pointer-checks < %s | FileCheck -check-prefix=NULL-VALID %s
3 3
4 // NULL-INVALID: define{{.*}} void @foo(i32* nonnull %x) 4 // NULL-INVALID: define{{.*}} void @foo(ptr noundef nonnull %x)
5 // NULL-VALID: define{{.*}} void @foo(i32* %x) 5 // NULL-VALID: define{{.*}} void @foo(ptr noundef %x)
6 void foo(int * __attribute__((nonnull)) x) { 6 void foo(int * __attribute__((nonnull)) x) {
7 *x = 0; 7 *x = 0;
8 } 8 }
9 9
10 // NULL-INVALID: define{{.*}} void @bar(i32* nonnull %x) 10 // NULL-INVALID: define{{.*}} void @bar(ptr noundef nonnull %x)
11 // NULL-VALID: define{{.*}} void @bar(i32* %x) 11 // NULL-VALID: define{{.*}} void @bar(ptr noundef %x)
12 void bar(int * x) __attribute__((nonnull(1))) { 12 void bar(int * x) __attribute__((nonnull(1))) {
13 *x = 0; 13 *x = 0;
14 } 14 }
15 15
16 // NULL-INVALID: define{{.*}} void @bar2(i32* %x, i32* nonnull %y) 16 // NULL-INVALID: define{{.*}} void @bar2(ptr noundef %x, ptr noundef nonnull %y)
17 // NULL-VALID: define{{.*}} void @bar2(i32* %x, i32* %y) 17 // NULL-VALID: define{{.*}} void @bar2(ptr noundef %x, ptr noundef %y)
18 void bar2(int * x, int * y) __attribute__((nonnull(2))) { 18 void bar2(int * x, int * y) __attribute__((nonnull(2))) {
19 *x = 0; 19 *x = 0;
20 } 20 }
21 21
22 static int a; 22 static int a;
23 // NULL-INVALID: define{{.*}} nonnull i32* @bar3() 23 // NULL-INVALID: define{{.*}} nonnull ptr @bar3()
24 // NULL-VALID: define{{.*}} i32* @bar3() 24 // NULL-VALID: define{{.*}} ptr @bar3()
25 int * bar3() __attribute__((returns_nonnull)) { 25 int * bar3(void) __attribute__((returns_nonnull)) {
26 return &a; 26 return &a;
27 } 27 }
28 28
29 // NULL-INVALID: define{{.*}} i32 @bar4(i32 %n, i32* nonnull %p) 29 // NULL-INVALID: define{{.*}} i32 @bar4(i32 noundef %n, ptr noundef nonnull %p)
30 // NULL-VALID: define{{.*}} i32 @bar4(i32 %n, i32* %p) 30 // NULL-VALID: define{{.*}} i32 @bar4(i32 noundef %n, ptr noundef %p)
31 int bar4(int n, int *p) __attribute__((nonnull)) { 31 int bar4(int n, int *p) __attribute__((nonnull)) {
32 return n + *p; 32 return n + *p;
33 } 33 }
34 34
35 // NULL-INVALID: define{{.*}} i32 @bar5(i32 %n, i32* nonnull %p) 35 // NULL-INVALID: define{{.*}} i32 @bar5(i32 noundef %n, ptr noundef nonnull %p)
36 // NULL-VALID: define{{.*}} i32 @bar5(i32 %n, i32* %p) 36 // NULL-VALID: define{{.*}} i32 @bar5(i32 noundef %n, ptr noundef %p)
37 int bar5(int n, int *p) __attribute__((nonnull(1, 2))) { 37 int bar5(int n, int *p) __attribute__((nonnull(1, 2))) {
38 return n + *p; 38 return n + *p;
39 } 39 }
40 40
41 typedef union { 41 typedef union {
48 // NULL-VALID: define{{.*}} i32 @bar6(i64 % 48 // NULL-VALID: define{{.*}} i32 @bar6(i64 %
49 int bar6(TransparentUnion tu) __attribute__((nonnull(1))) { 49 int bar6(TransparentUnion tu) __attribute__((nonnull(1))) {
50 return *tu.p; 50 return *tu.p;
51 } 51 }
52 52
53 // NULL-INVALID: define{{.*}} void @bar7(i32* nonnull %a, i32* nonnull %b) 53 // NULL-INVALID: define{{.*}} void @bar7(ptr noundef nonnull %a, ptr noundef nonnull %b)
54 // NULL-VALID: define{{.*}} void @bar7(i32* %a, i32* %b) 54 // NULL-VALID: define{{.*}} void @bar7(ptr noundef %a, ptr noundef %b)
55 void bar7(int *a, int *b) __attribute__((nonnull(1))) 55 void bar7(int *a, int *b) __attribute__((nonnull(1)))
56 __attribute__((nonnull(2))) {} 56 __attribute__((nonnull(2))) {}
57 57
58 // NULL-INVALID: define{{.*}} void @bar8(i32* nonnull %a, i32* nonnull %b) 58 // NULL-INVALID: define{{.*}} void @bar8(ptr noundef nonnull %a, ptr noundef nonnull %b)
59 // NULL-VALID: define{{.*}} void @bar8(i32* %a, i32* %b) 59 // NULL-VALID: define{{.*}} void @bar8(ptr noundef %a, ptr noundef %b)
60 void bar8(int *a, int *b) __attribute__((nonnull)) 60 void bar8(int *a, int *b) __attribute__((nonnull))
61 __attribute__((nonnull(1))) {} 61 __attribute__((nonnull(1))) {}