annotate clang/test/CodeGen/nonnull.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -check-prefix=NULL-INVALID %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -fno-delete-null-pointer-checks < %s | FileCheck -check-prefix=NULL-VALID %s
anatofuz
parents:
diff changeset
3
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
4 // NULL-INVALID: define{{.*}} void @foo(i32* nonnull %x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
5 // NULL-VALID: define{{.*}} void @foo(i32* %x)
150
anatofuz
parents:
diff changeset
6 void foo(int * __attribute__((nonnull)) x) {
anatofuz
parents:
diff changeset
7 *x = 0;
anatofuz
parents:
diff changeset
8 }
anatofuz
parents:
diff changeset
9
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
10 // NULL-INVALID: define{{.*}} void @bar(i32* nonnull %x)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
11 // NULL-VALID: define{{.*}} void @bar(i32* %x)
150
anatofuz
parents:
diff changeset
12 void bar(int * x) __attribute__((nonnull(1))) {
anatofuz
parents:
diff changeset
13 *x = 0;
anatofuz
parents:
diff changeset
14 }
anatofuz
parents:
diff changeset
15
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
16 // NULL-INVALID: define{{.*}} void @bar2(i32* %x, i32* nonnull %y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
17 // NULL-VALID: define{{.*}} void @bar2(i32* %x, i32* %y)
150
anatofuz
parents:
diff changeset
18 void bar2(int * x, int * y) __attribute__((nonnull(2))) {
anatofuz
parents:
diff changeset
19 *x = 0;
anatofuz
parents:
diff changeset
20 }
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 static int a;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
23 // NULL-INVALID: define{{.*}} nonnull i32* @bar3()
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
24 // NULL-VALID: define{{.*}} i32* @bar3()
150
anatofuz
parents:
diff changeset
25 int * bar3() __attribute__((returns_nonnull)) {
anatofuz
parents:
diff changeset
26 return &a;
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
29 // NULL-INVALID: define{{.*}} i32 @bar4(i32 %n, i32* nonnull %p)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
30 // NULL-VALID: define{{.*}} i32 @bar4(i32 %n, i32* %p)
150
anatofuz
parents:
diff changeset
31 int bar4(int n, int *p) __attribute__((nonnull)) {
anatofuz
parents:
diff changeset
32 return n + *p;
anatofuz
parents:
diff changeset
33 }
anatofuz
parents:
diff changeset
34
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
35 // NULL-INVALID: define{{.*}} i32 @bar5(i32 %n, i32* nonnull %p)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
36 // NULL-VALID: define{{.*}} i32 @bar5(i32 %n, i32* %p)
150
anatofuz
parents:
diff changeset
37 int bar5(int n, int *p) __attribute__((nonnull(1, 2))) {
anatofuz
parents:
diff changeset
38 return n + *p;
anatofuz
parents:
diff changeset
39 }
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 typedef union {
anatofuz
parents:
diff changeset
42 unsigned long long n;
anatofuz
parents:
diff changeset
43 int *p;
anatofuz
parents:
diff changeset
44 double d;
anatofuz
parents:
diff changeset
45 } TransparentUnion __attribute__((transparent_union));
anatofuz
parents:
diff changeset
46
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
47 // NULL-INVALID: define{{.*}} i32 @bar6(i64 %
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
48 // NULL-VALID: define{{.*}} i32 @bar6(i64 %
150
anatofuz
parents:
diff changeset
49 int bar6(TransparentUnion tu) __attribute__((nonnull(1))) {
anatofuz
parents:
diff changeset
50 return *tu.p;
anatofuz
parents:
diff changeset
51 }
anatofuz
parents:
diff changeset
52
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
53 // NULL-INVALID: define{{.*}} void @bar7(i32* nonnull %a, i32* nonnull %b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
54 // NULL-VALID: define{{.*}} void @bar7(i32* %a, i32* %b)
150
anatofuz
parents:
diff changeset
55 void bar7(int *a, int *b) __attribute__((nonnull(1)))
anatofuz
parents:
diff changeset
56 __attribute__((nonnull(2))) {}
anatofuz
parents:
diff changeset
57
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
58 // NULL-INVALID: define{{.*}} void @bar8(i32* nonnull %a, i32* nonnull %b)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
59 // NULL-VALID: define{{.*}} void @bar8(i32* %a, i32* %b)
150
anatofuz
parents:
diff changeset
60 void bar8(int *a, int *b) __attribute__((nonnull))
anatofuz
parents:
diff changeset
61 __attribute__((nonnull(1))) {}