diff options
author | Vedant Kumar <vsk@apple.com> | 2018-06-26 02:50:04 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-06-26 02:50:04 +0000 |
commit | 03dd150a988eb28b29ef24c3202b09e37e1de80f (patch) | |
tree | 183a0337016c9b9616b6fa01c7dd4de39d4541a0 /clang/test/CodeGenObjC | |
parent | 2a46384c21a93d827d624e8d00c16377a5c0c12c (diff) | |
download | bcm5719-llvm-03dd150a988eb28b29ef24c3202b09e37e1de80f.tar.gz bcm5719-llvm-03dd150a988eb28b29ef24c3202b09e37e1de80f.zip |
[ubsan] Relax nullability-return for blocks with deduced types
When the return type of an ObjC-style block literals is deduced, pick
the candidate type with the strictest nullability annotation applicable
to every other candidate.
This suppresses a UBSan false-positive in situations where a too-strict
nullability would be deduced, despite the fact that the returned value
would be implicitly cast to _Nullable.
rdar://41317163
llvm-svn: 335572
Diffstat (limited to 'clang/test/CodeGenObjC')
-rw-r--r-- | clang/test/CodeGenObjC/ubsan-nullability.m | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/clang/test/CodeGenObjC/ubsan-nullability.m b/clang/test/CodeGenObjC/ubsan-nullability.m index eeb24b03c86..8e7a9cba7c7 100644 --- a/clang/test/CodeGenObjC/ubsan-nullability.m +++ b/clang/test/CodeGenObjC/ubsan-nullability.m @@ -1,6 +1,6 @@ // REQUIRES: asserts -// RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s -// RUN: %clang_cc1 -x objective-c++ -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s +// RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fblocks -fobjc-arc -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s +// RUN: %clang_cc1 -x objective-c++ -emit-llvm -triple x86_64-apple-macosx10.10.0 -fblocks -fobjc-arc -fsanitize=nullability-arg,nullability-assign,nullability-return -w %s -o - | FileCheck %s // CHECK: [[NONNULL_RV_LOC1:@.*]] = private unnamed_addr global {{.*}} i32 100, i32 6 // CHECK: [[NONNULL_ARG_LOC:@.*]] = private unnamed_addr global {{.*}} i32 204, i32 15 {{.*}} i32 190, i32 23 @@ -177,6 +177,37 @@ void call_A(A *a, int *p) { void dont_crash(int *_Nonnull p, ...) {} +@protocol NSObject +- (id)init; +@end +@interface NSObject <NSObject> {} +@end + +#pragma clang assume_nonnull begin + +/// Create a "NSObject * _Nonnull" instance. +NSObject *get_nonnull_error() { + // Use nil for convenience. The actual object doesn't matter. + return (NSObject *)NULL; +} + +NSObject *_Nullable no_null_return_value_diagnostic(int flag) { +// CHECK-LABEL: define internal {{.*}}no_null_return_value_diagnostic{{i?}}_block_invoke +// CHECK-NOT: @__ubsan_handle_nullability_return + NSObject *_Nullable (^foo)() = ^() { + if (flag) { + // Clang should not infer a nonnull return value for this block when this + // call is present. + return get_nonnull_error(); + } else { + return (NSObject *)NULL; + } + }; + return foo(); +} + +#pragma clang assume_nonnull end + int main() { nonnull_retval1(INULL); nonnull_retval2(INNULL, INNULL, INULL, (int *_Nullable)NULL, 0, 0, 0, 0); @@ -188,5 +219,7 @@ int main() { nonnull_init2(INULL); call_A((A *)NULL, INULL); dont_crash(INNULL, NULL); + no_null_return_value_diagnostic(0); + no_null_return_value_diagnostic(1); return 0; } |