r299992 - [Sema][ObjC] Check whether a variable has a definition, rather than
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 11 15:01:33 PDT 2017
Author: ahatanak
Date: Tue Apr 11 17:01:33 2017
New Revision: 299992
URL: http://llvm.org/viewvc/llvm-project?rev=299992&view=rev
Log:
[Sema][ObjC] Check whether a variable has a definition, rather than
checking its storage class, when determining whether casting a C pointer
to an ObjC pointer is allowed.
This change allows casting variables whose declarations are directly
contained in a linkage specification to an ObjC pointer type. Those
variables are treated as if they contain the extern specifier for the
purpose of determining whether they are definitions or not.
rdar://problem/29249853
Differential Revision: https://reviews.llvm.org/D31673
Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=299992&r1=299991&r2=299992&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Apr 11 17:01:33 2017
@@ -3355,7 +3355,7 @@ namespace {
if (isAnyRetainable(TargetClass) &&
isAnyRetainable(SourceClass) &&
var &&
- var->getStorageClass() == SC_Extern &&
+ !var->hasDefinition(Context) &&
var->getType().isConstQualified()) {
// In system headers, they can also be assumed to be immune to retains.
Modified: cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm?rev=299992&r1=299991&r2=299992&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm (original)
+++ cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm Tue Apr 11 17:01:33 2017
@@ -52,3 +52,19 @@ void testObjCBridgeId() {
ref = (__bridge_retained CFAnnotatedObjectRef) CreateSomething();
ref = (__bridge_retained CFAnnotatedObjectRef) CreateNSString();
}
+
+struct __CFAnnotatedObject {
+} cf0;
+
+extern const CFAnnotatedObjectRef r0;
+extern const CFAnnotatedObjectRef r1 = &cf0;
+extern "C" const CFAnnotatedObjectRef r2;
+extern "C" const CFAnnotatedObjectRef r3 = &cf0;
+
+void testExternC() {
+ id obj;
+ obj = (id)r0;
+ obj = (id)r1; // expected-error{{cast of C pointer type 'CFAnnotatedObjectRef' (aka 'const __CFAnnotatedObject *') to Objective-C pointer type 'id' requires a bridged cast}} expected-note{{use __bridge to convert directly}} expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFAnnotatedObjectRef'}}
+ obj = (id)r2;
+ obj = (id)r3; // expected-error{{cast of C pointer type 'CFAnnotatedObjectRef' (aka 'const __CFAnnotatedObject *') to Objective-C pointer type 'id' requires a bridged cast}} expected-note{{use __bridge to convert directly}} expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFAnnotatedObjectRef'}}
+}
More information about the cfe-commits
mailing list