summaryrefslogtreecommitdiff
path: root/test/CodeGenObjC
diff options
context:
space:
mode:
authorKuba Mracek <mracek@apple.com>2017-06-30 16:28:15 +0000
committerKuba Mracek <mracek@apple.com>2017-06-30 16:28:15 +0000
commitfc0baba7f6ae7a67b39c2375bfbbb7948a10b026 (patch)
tree126b3de1536316bf9df5d1bdc20064417eb6482c /test/CodeGenObjC
parent75ec5aa40177caeb6531afab8c0757183dddc101 (diff)
[objc] Don't require null-check and don't emit memset when result is ignored for struct-returning method calls [clang 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/cfe/trunk@306837 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenObjC')
-rw-r--r--test/CodeGenObjC/stret-1.m11
-rw-r--r--test/CodeGenObjC/stret-lifetime.m34
2 files changed, 44 insertions, 1 deletions
diff --git a/test/CodeGenObjC/stret-1.m b/test/CodeGenObjC/stret-1.m
index a7bcdda48b..2314d5a9ec 100644
--- a/test/CodeGenObjC/stret-1.m
+++ b/test/CodeGenObjC/stret-1.m
@@ -12,11 +12,20 @@ struct stret one = {{1}};
int main(int argc, const char **argv)
{
- [(id)(argc&~255) method];
+ struct stret s;
+ s = [(id)(argc&~255) method];
// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T0:%[^,]+]]
// CHECK: [[T0P:%.*]] = bitcast %struct.stret* [[T0]] to i8*
// CHECK: call void @llvm.memset.p0i8.i64(i8* [[T0P]], i8 0, i64 400, i32 4, i1 false)
+ s = [Test method];
+ // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T1:%[^,]+]]
+ // CHECK-NOT: call void @llvm.memset.p0i8.i64(
+
+ [(id)(argc&~255) method];
+ // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T1:%[^,]+]]
+ // CHECK-NOT: call void @llvm.memset.p0i8.i64(
+
[Test method];
// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (%struct.stret*, i8*, i8*)*)(%struct.stret* sret [[T1:%[^,]+]]
// CHECK-NOT: call void @llvm.memset.p0i8.i64(
diff --git a/test/CodeGenObjC/stret-lifetime.m b/test/CodeGenObjC/stret-lifetime.m
new file mode 100644
index 0000000000..d81ef34aee
--- /dev/null
+++ b/test/CodeGenObjC/stret-lifetime.m
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple arm64-apple-darwin -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-darwin -fobjc-arc -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK,ARC
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -S -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s --check-prefixes=CHECK,ARC
+
+struct stret { int x[100]; };
+struct stret one = {{1}};
+
+@interface Test
++(struct stret) method;
++(struct stret) methodConsuming:(id __attribute__((ns_consumed)))consumed;
+@end
+
+void foo(id o, id p) {
+ [o method];
+ // CHECK: @llvm.lifetime.start
+ // CHECK: call void bitcast {{.*}} @objc_msgSend
+ // CHECK: @llvm.lifetime.end
+ // CHECK-NOT: call void @llvm.memset
+
+ [o methodConsuming:p];
+ // ARC: [[T0:%.*]] = icmp eq i8*
+ // ARC: br i1 [[T0]]
+
+ // CHECK: @llvm.lifetime.start
+ // CHECK: call void bitcast {{.*}} @objc_msgSend
+ // CHECK: @llvm.lifetime.end
+ // ARC: br label
+
+ // ARC: call void @objc_release
+ // ARC: br label
+
+ // CHECK-NOT: call void @llvm.memset
+}