diff options
author | Kuba Mracek <mracek@apple.com> | 2017-06-30 16:29:43 +0000 |
---|---|---|
committer | Kuba Mracek <mracek@apple.com> | 2017-06-30 16:29:43 +0000 |
commit | f0fdf665b4d351c308557383fadae7828660f499 (patch) | |
tree | b2b861ace68044f039bdf48c171d316a8c55c2dd /test | |
parent | 63de5fcd7287d033a1667de42831c293137e00e4 (diff) |
[objc] Don't require null-check and don't emit memset when result is ignored for struct-returning method calls [compiler-rt part]
This fixes an issue with the emission of lifetime markers for struct-returning Obj-C msgSend calls. When the result of a struct-returning call is ignored, the temporary storage is only marked with lifetime markers in one of the two branches of the nil-receiver-check. The check is, however, not required when the result is unused. If we still need to emit the check (due to consumer arguments), let's not emit the memset to zero out the result if it's unused. This fixes a use-after-scope false positive with AddressSanitizer.
Differential Revision: https://reviews.llvm.org/D34834
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306838 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/asan/TestCases/Darwin/nil-return-struct.mm | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/asan/TestCases/Darwin/nil-return-struct.mm b/test/asan/TestCases/Darwin/nil-return-struct.mm new file mode 100644 index 000000000..9fb77e746 --- /dev/null +++ b/test/asan/TestCases/Darwin/nil-return-struct.mm @@ -0,0 +1,31 @@ +// RUN: %clang_asan %s -o %t -framework Foundation +// RUN: %run %t 2>&1 | FileCheck %s + +#import <Foundation/Foundation.h> + +struct MyStruct { + long a, b, c, d; +}; + +@interface MyClass: NSObject +- (MyStruct)methodWhichReturnsARect; +@end +@implementation MyClass +- (MyStruct)methodWhichReturnsARect { + MyStruct s; + s.a = 10; + s.b = 20; + s.c = 30; + s.d = 40; + return s; +} +@end + +int main() { + MyClass *myNil = nil; // intentionally nil + [myNil methodWhichReturnsARect]; + fprintf(stderr, "Hello world"); +} + +// CHECK-NOT: AddressSanitizer: stack-use-after-scope +// CHECK: Hello world |