mwyman updated this revision to Diff 410863.
mwyman added a comment.

Added new inner scope for test file.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120372/new/

https://reviews.llvm.org/D120372

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaObjC/objc-precise-lifetime-unused-variable.m


Index: clang/test/SemaObjC/objc-precise-lifetime-unused-variable.m
===================================================================
--- /dev/null
+++ clang/test/SemaObjC/objc-precise-lifetime-unused-variable.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -fsyntax-only -fobjc-arc 
-fblocks -verify -Wunused-but-set-variable -Wno-objc-root-class %s
+
+id getFoo(void);
+
+void test() {
+  // no diagnostics for objects with precise lifetime semantics.
+  __attribute__((objc_precise_lifetime)) id x;
+  x = getFoo();
+
+  id x2; // expected-warning {{variable 'x2' set but not used}}
+  x2 = getFoo();
+
+  do {
+    __attribute__((objc_precise_lifetime)) id y;
+    y = getFoo();
+
+    id y2; // expected-warning {{variable 'y2' set but not used}}
+    y2 = getFoo();
+  } while(0);
+
+  x = ((void *)0);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2008,6 +2008,12 @@
   if (VD->hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
     return;
 
+  // Don't warn about Objective-C pointer variables with precise lifetime
+  // semantics; they can be used to ensure ARC releases the object at a known
+  // time, which may mean assignment but no other references.
+  if (VD->hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
+    return;
+
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())
     return;


Index: clang/test/SemaObjC/objc-precise-lifetime-unused-variable.m
===================================================================
--- /dev/null
+++ clang/test/SemaObjC/objc-precise-lifetime-unused-variable.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos11 -fsyntax-only -fobjc-arc -fblocks -verify -Wunused-but-set-variable -Wno-objc-root-class %s
+
+id getFoo(void);
+
+void test() {
+  // no diagnostics for objects with precise lifetime semantics.
+  __attribute__((objc_precise_lifetime)) id x;
+  x = getFoo();
+
+  id x2; // expected-warning {{variable 'x2' set but not used}}
+  x2 = getFoo();
+
+  do {
+    __attribute__((objc_precise_lifetime)) id y;
+    y = getFoo();
+
+    id y2; // expected-warning {{variable 'y2' set but not used}}
+    y2 = getFoo();
+  } while(0);
+
+  x = ((void *)0);
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -2008,6 +2008,12 @@
   if (VD->hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
     return;
 
+  // Don't warn about Objective-C pointer variables with precise lifetime
+  // semantics; they can be used to ensure ARC releases the object at a known
+  // time, which may mean assignment but no other references.
+  if (VD->hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
+    return;
+
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())
     return;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to