[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

llvm-svn: 316531
This commit is contained in:
Akira Hatanaka 2017-10-24 23:38:14 +00:00
parent c677268721
commit bc1d56eafa
3 changed files with 31 additions and 6 deletions

View File

@ -3482,13 +3482,20 @@ classifyPointerDeclarator(Sema &S, QualType type, Declarator &declarator,
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;
}
}
}

View File

@ -0,0 +1,13 @@
@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

View File

@ -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"