brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 8bf4e53 Raw
62 lines · c
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm < %s | FileCheck -check-prefix=NULL-INVALID %s2// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -fno-delete-null-pointer-checks < %s | FileCheck -check-prefix=NULL-VALID %s3 4// NULL-INVALID: define{{.*}} void @foo(ptr noundef nonnull %x)5// NULL-VALID: define{{.*}} void @foo(ptr noundef %x)6void foo(int * __attribute__((nonnull)) x) {7  *x = 0;8}9 10// NULL-INVALID: define{{.*}} void @bar(ptr noundef nonnull %x)11// NULL-VALID: define{{.*}} void @bar(ptr noundef %x)12void bar(int * x) __attribute__((nonnull(1)))  {13  *x = 0;14}15 16// NULL-INVALID: define{{.*}} void @bar2(ptr noundef %x, ptr noundef nonnull %y)17// NULL-VALID: define{{.*}} void @bar2(ptr noundef %x, ptr noundef %y)18void bar2(int * x, int * y) __attribute__((nonnull(2)))  {19  *x = 0;20}21 22static int a;23// NULL-INVALID: define{{.*}} nonnull ptr @bar3()24// NULL-VALID: define{{.*}} ptr @bar3()25int * bar3(void) __attribute__((returns_nonnull))  {26  return &a;27}28 29// NULL-INVALID: define{{.*}} i32 @bar4(i32 noundef %n, ptr noundef nonnull %p)30// NULL-VALID: define{{.*}} i32 @bar4(i32 noundef %n, ptr noundef %p)31int bar4(int n, int *p) __attribute__((nonnull)) {32  return n + *p;33}34 35// NULL-INVALID: define{{.*}} i32 @bar5(i32 noundef %n, ptr noundef nonnull %p)36// NULL-VALID: define{{.*}} i32 @bar5(i32 noundef %n, ptr noundef %p)37int bar5(int n, int *p) __attribute__((nonnull(1, 2))) {38  return n + *p;39}40 41typedef union {42  unsigned long long n;43  int *p;44  double d;45} TransparentUnion __attribute__((transparent_union));46 47// NULL-INVALID: define{{.*}} i32 @bar6(i64 %48// NULL-VALID: define{{.*}} i32 @bar6(i64 %49int bar6(TransparentUnion tu) __attribute__((nonnull(1))) {50  return *tu.p;51}52 53// NULL-INVALID: define{{.*}} void @bar7(ptr noundef nonnull %a, ptr noundef nonnull %b)54// NULL-VALID: define{{.*}} void @bar7(ptr noundef %a, ptr noundef %b)55void bar7(int *a, int *b) __attribute__((nonnull(1)))56__attribute__((nonnull(2))) {}57 58// NULL-INVALID: define{{.*}} void @bar8(ptr noundef nonnull %a, ptr noundef nonnull %b)59// NULL-VALID: define{{.*}} void @bar8(ptr noundef %a, ptr noundef %b)60void bar8(int *a, int *b) __attribute__((nonnull))61__attribute__((nonnull(1))) {}62