]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenObjC/ubsan-nonnull-and-nullability.m
Vendor import of clang trunk r300422:
[FreeBSD/FreeBSD.git] / test / CodeGenObjC / ubsan-nonnull-and-nullability.m
1 // REQUIRES: asserts
2 // RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-return,returns-nonnull-attribute,nullability-arg,nonnull-attribute %s -o - -w | FileCheck %s
3
4 // If both the annotation and the attribute are present, prefer the attribute,
5 // since it actually affects IRGen.
6
7 // CHECK-LABEL: define nonnull i32* @f1
8 __attribute__((returns_nonnull)) int *_Nonnull f1(int *_Nonnull p) {
9   // CHECK: entry:
10   // CHECK-NEXT: [[ADDR:%.*]] = alloca i32*
11   // CHECK-NEXT: store i32* [[P:%.*]], i32** [[ADDR]]
12   // CHECK-NEXT: [[ARG:%.*]] = load i32*, i32** [[ADDR]]
13   // CHECK-NEXT: [[ICMP:%.*]] = icmp ne i32* [[ARG]], null, !nosanitize
14   // CHECK-NEXT: br i1 [[ICMP]], label %[[CONT:.+]], label %[[HANDLE:[^,]+]]
15   // CHECK: [[HANDLE]]:
16   // CHECK-NEXT:   call void @__ubsan_handle_nonnull_return_abort
17   // CHECK-NEXT:   unreachable, !nosanitize
18   // CHECK: [[CONT]]:
19   // CHECK-NEXT:   ret i32*
20   return p;
21 }
22
23 // CHECK-LABEL: define void @f2
24 void f2(int *_Nonnull __attribute__((nonnull)) p) {}
25
26 // CHECK-LABEL: define void @call_f2
27 void call_f2() {
28   // CHECK: call void @__ubsan_handle_nonnull_arg_abort
29   // CHECK-NOT: call void @__ubsan_handle_nonnull_arg_abort
30   f2((void *)0);
31 }