summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKuba Mracek <mracek@apple.com>2017-06-30 16:29:43 +0000
committerKuba Mracek <mracek@apple.com>2017-06-30 16:29:43 +0000
commitc41ba09433e48f4a3f760971971ae33ab08a1157 (patch)
tree03e56acc912c1a55c5e354db6e74ffcc90df8cad
parentbce5ceabea38f285e52d32480c7040855320ef7d (diff)
downloadbcm5719-llvm-c41ba09433e48f4a3f760971971ae33ab08a1157.tar.gz
bcm5719-llvm-c41ba09433e48f4a3f760971971ae33ab08a1157.zip
[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 llvm-svn: 306838
-rw-r--r--compiler-rt/test/asan/TestCases/Darwin/nil-return-struct.mm31
1 files changed, 31 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Darwin/nil-return-struct.mm b/compiler-rt/test/asan/TestCases/Darwin/nil-return-struct.mm
new file mode 100644
index 00000000000..9fb77e74633
--- /dev/null
+++ b/compiler-rt/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
OpenPOWER on IntegriCloud