[compiler-rt] r306838 - [objc] Don't require null-check and don't emit memset when result is ignored for struct-returning method calls [compiler-rt part]

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 30 09:29:43 PDT 2017


Author: kuba.brecka
Date: Fri Jun 30 09:29:43 2017
New Revision: 306838

URL: http://llvm.org/viewvc/llvm-project?rev=306838&view=rev
Log:
[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


Added:
    compiler-rt/trunk/test/asan/TestCases/Darwin/nil-return-struct.mm

Added: compiler-rt/trunk/test/asan/TestCases/Darwin/nil-return-struct.mm
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/nil-return-struct.mm?rev=306838&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/nil-return-struct.mm (added)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/nil-return-struct.mm Fri Jun 30 09:29:43 2017
@@ -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;
+};
+
+ at interface MyClass: NSObject
+- (MyStruct)methodWhichReturnsARect;
+ at end
+ at implementation MyClass
+- (MyStruct)methodWhichReturnsARect {
+  MyStruct s;
+  s.a = 10;
+  s.b = 20;
+  s.c = 30;
+  s.d = 40;
+  return s;
+}
+ at end
+
+int main() {
+  MyClass *myNil = nil;  // intentionally nil
+  [myNil methodWhichReturnsARect];
+  fprintf(stderr, "Hello world");
+}
+
+// CHECK-NOT: AddressSanitizer: stack-use-after-scope
+// CHECK: Hello world




More information about the llvm-commits mailing list