File: nonnull.c

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (61 lines) | stat: -rw-r--r-- 2,279 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -check-prefix=NULL-INVALID %s
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin -emit-llvm -fno-delete-null-pointer-checks < %s | FileCheck -check-prefix=NULL-VALID %s

// NULL-INVALID: define{{.*}} void @foo(i32* noundef nonnull %x)
// NULL-VALID: define{{.*}} void @foo(i32* noundef %x)
void foo(int * __attribute__((nonnull)) x) {
  *x = 0;
}

// NULL-INVALID: define{{.*}} void @bar(i32* noundef nonnull %x)
// NULL-VALID: define{{.*}} void @bar(i32* noundef %x)
void bar(int * x) __attribute__((nonnull(1)))  {
  *x = 0;
}

// NULL-INVALID: define{{.*}} void @bar2(i32* noundef %x, i32* noundef nonnull %y)
// NULL-VALID: define{{.*}} void @bar2(i32* noundef %x, i32* noundef %y)
void bar2(int * x, int * y) __attribute__((nonnull(2)))  {
  *x = 0;
}

static int a;
// NULL-INVALID: define{{.*}} nonnull i32* @bar3()
// NULL-VALID: define{{.*}} i32* @bar3()
int * bar3(void) __attribute__((returns_nonnull))  {
  return &a;
}

// NULL-INVALID: define{{.*}} i32 @bar4(i32 noundef %n, i32* noundef nonnull %p)
// NULL-VALID: define{{.*}} i32 @bar4(i32 noundef %n, i32* noundef %p)
int bar4(int n, int *p) __attribute__((nonnull)) {
  return n + *p;
}

// NULL-INVALID: define{{.*}} i32 @bar5(i32 noundef %n, i32* noundef nonnull %p)
// NULL-VALID: define{{.*}} i32 @bar5(i32 noundef %n, i32* noundef %p)
int bar5(int n, int *p) __attribute__((nonnull(1, 2))) {
  return n + *p;
}

typedef union {
  unsigned long long n;
  int *p;
  double d;
} TransparentUnion __attribute__((transparent_union));

// NULL-INVALID: define{{.*}} i32 @bar6(i64 %
// NULL-VALID: define{{.*}} i32 @bar6(i64 %
int bar6(TransparentUnion tu) __attribute__((nonnull(1))) {
  return *tu.p;
}

// NULL-INVALID: define{{.*}} void @bar7(i32* noundef nonnull %a, i32* noundef nonnull %b)
// NULL-VALID: define{{.*}} void @bar7(i32* noundef %a, i32* noundef %b)
void bar7(int *a, int *b) __attribute__((nonnull(1)))
__attribute__((nonnull(2))) {}

// NULL-INVALID: define{{.*}} void @bar8(i32* noundef nonnull %a, i32* noundef nonnull %b)
// NULL-VALID: define{{.*}} void @bar8(i32* noundef %a, i32* noundef %b)
void bar8(int *a, int *b) __attribute__((nonnull))
__attribute__((nonnull(1))) {}