r316531 - [Sema][ObjC] Look for either objc_bridge or objc_bridge_mutable when

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 24 16:38:14 PDT 2017


Author: ahatanak
Date: Tue Oct 24 16:38:14 2017
New Revision: 316531

URL: http://llvm.org/viewvc/llvm-project?rev=316531&view=rev
Log:
[Sema][ObjC] Look for either objc_bridge or objc_bridge_mutable when
determining whether a RecordDecl is CFError.

CFErrorRef used to be declared with "objc_bridge(NSError)" but is now
declared with "objc_bridge_mutable(NSError)". Look for either when
checking whether a RecordDecl is CFError.

rdar://problem/35034779

Added:
    cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h
    cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm
Modified:
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=316531&r1=316530&r2=316531&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Oct 24 16:38:14 2017
@@ -3482,13 +3482,20 @@ classifyPointerDeclarator(Sema &S, QualT
         isCFError = (S.CFError == recordDecl);
       } else {
         // Check whether this is CFError, which we identify based on its bridge
-        // to NSError.
+        // to NSError. CFErrorRef used to be declared with "objc_bridge" but is
+        // now declared with "objc_bridge_mutable", so look for either one of
+        // the two attributes.
         if (recordDecl->getTagKind() == TTK_Struct && numNormalPointers > 0) {
-          if (auto bridgeAttr = recordDecl->getAttr<ObjCBridgeAttr>()) {
-            if (bridgeAttr->getBridgedType() == S.getNSErrorIdent()) {
-              S.CFError = recordDecl;
-              isCFError = true;
-            }
+          IdentifierInfo *bridgedType = nullptr;
+          if (auto bridgeAttr = recordDecl->getAttr<ObjCBridgeAttr>())
+            bridgedType = bridgeAttr->getBridgedType();
+          else if (auto bridgeAttr =
+                       recordDecl->getAttr<ObjCBridgeMutableAttr>())
+            bridgedType = bridgeAttr->getBridgedType();
+
+          if (bridgedType == S.getNSErrorIdent()) {
+            S.CFError = recordDecl;
+            isCFError = true;
           }
         }
       }

Added: cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h?rev=316531&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h (added)
+++ cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h Tue Oct 24 16:38:14 2017
@@ -0,0 +1,13 @@
+ at class NSError;
+
+#pragma clang assume_nonnull begin
+
+#ifdef USE_MUTABLE
+typedef struct __attribute__((objc_bridge_mutable(NSError))) __CFError * CFErrorRef;
+#else
+typedef struct __attribute__((objc_bridge(NSError))) __CFError * CFErrorRef;
+#endif
+
+void func1(CFErrorRef *error);
+
+#pragma clang assume_nonnull end

Added: cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm?rev=316531&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm (added)
+++ cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm Tue Oct 24 16:38:14 2017
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs -x objective-c -Wnullability-completeness -Werror -verify %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs -x objective-c -Wnullability-completeness -Werror -verify -DUSE_MUTABLE %s
+// expected-no-diagnostics
+
+#include "nullability-completeness-cferror.h"




More information about the cfe-commits mailing list