blob: 7c33e6329fddff8e07fd98ef03a99b7d9dca70dc [file] [log] [blame]
Hal Finkel82504f02014-07-11 17:35:21 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck %s
2
3// CHECK: define void @foo(i32* nonnull %x)
4void foo(int * __attribute__((nonnull)) x) {
5 *x = 0;
6}
7
8// CHECK: define void @bar(i32* nonnull %x)
9void bar(int * x) __attribute__((nonnull(1))) {
10 *x = 0;
11}
12
13// CHECK: define void @bar2(i32* %x, i32* nonnull %y)
14void bar2(int * x, int * y) __attribute__((nonnull(2))) {
15 *x = 0;
16}
17
Hal Finkeld8442b12014-07-12 04:51:04 +000018static int a;
19// CHECK: define nonnull i32* @bar3()
20int * bar3() __attribute__((returns_nonnull)) {
21 return &a;
22}
23
Richard Smith00cc1c02014-08-27 18:56:18 +000024// CHECK: define i32 @bar4(i32 %n, i32* nonnull %p)
25int bar4(int n, int *p) __attribute__((nonnull)) {
26 return n + *p;
27}
28
29// CHECK: define i32 @bar5(i32 %n, i32* nonnull %p)
30int bar5(int n, int *p) __attribute__((nonnull(1, 2))) {
31 return n + *p;
32}
33
34typedef union {
35 unsigned long long n;
36 int *p;
37 double d;
38} TransparentUnion __attribute__((transparent_union));
39
40// CHECK: define i32 @bar6(i64 %
41int bar6(TransparentUnion tu) __attribute__((nonnull(1))) {
42 return *tu.p;
43}
Alexey Samsonov9fc9bf82014-08-28 00:53:20 +000044
45// CHECK: define void @bar7(i32* nonnull %a, i32* nonnull %b)
46void bar7(int *a, int *b) __attribute__((nonnull(1)))
47__attribute__((nonnull(2))) {}
48
49// CHECK: define void @bar8(i32* nonnull %a, i32* nonnull %b)
50void bar8(int *a, int *b) __attribute__((nonnull))
51__attribute__((nonnull(1))) {}