r195066 - ObjectiveC 'objc_bridging'. Assorment of improvements

Fariborz Jahanian fjahanian at apple.com
Mon Nov 18 17:23:07 PST 2013


Author: fjahanian
Date: Mon Nov 18 19:23:07 2013
New Revision: 195066

URL: http://llvm.org/viewvc/llvm-project?rev=195066&view=rev
Log:
ObjectiveC 'objc_bridging'. Assorment of improvements 
per Doug/Jordan comments. // rdar://15454846.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/objcbridge-attribute.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=195066&r1=195065&r2=195066&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon Nov 18 19:23:07 2013
@@ -382,7 +382,7 @@ def AutomaticReferenceCounting : DiagGro
 def ARCRepeatedUseOfWeakMaybe : DiagGroup<"arc-maybe-repeated-use-of-weak">;
 def ARCRepeatedUseOfWeak : DiagGroup<"arc-repeated-use-of-weak",
                                      [ARCRepeatedUseOfWeakMaybe]>;
-def ObjCBridge : DiagGroup<"arc-bridge-cast">;
+def ObjCBridge : DiagGroup<"bridge-cast">;
 
 def SelectorTypeMismatch : DiagGroup<"selector-type-mismatch">;
 def Selector : DiagGroup<"selector", [SelectorTypeMismatch]>;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=195066&r1=195065&r2=195066&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Nov 18 19:23:07 2013
@@ -2442,9 +2442,7 @@ def err_ns_bridged_not_interface : Error
 def err_objc_bridge_not_id : Error<
   "parameter of 'objc_bridge' attribute must be a single name of an Objective-C class">;
 def err_objc_bridge_attribute : Error<
-  "'objc_bridge' attribute must be applied to a struct, C++ class, or union">;
-def err_objc_bridge_not_cftype : Error<
-  "'objc_bridge' attribute must be applied to definition of CF types">;
+  "'objc_bridge' attribute must be applied to a struct%select{|, C++ class}0 or union">;
 def err_objc_cf_bridged_not_interface : Error<
   "CF object of type %0 is bridged to '%1', which is not an Objective-C class">;
 def err_objc_ns_bridged_invalid_cfobject : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=195066&r1=195065&r2=195066&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Nov 18 19:23:07 2013
@@ -10072,31 +10072,6 @@ void Sema::AddKnownFunctionAttributes(Fu
   }
 }
 
-static inline bool isTollFreeBridgeCFRefType(TypedefDecl *TD) {
-  TypedefNameDecl * TDefNameDecl = TD;
-  const Type *TP = TDefNameDecl->getUnderlyingType().getTypePtr();
-  while (const TypedefType *TDef = dyn_cast<TypedefType>(TP)) {
-    TDefNameDecl = TDef->getDecl();
-    TP = TDefNameDecl->getUnderlyingType().getTypePtr();
-  }
-  
-  StringRef TDName = TDefNameDecl->getIdentifier()->getName();
-  return (TDName.startswith("CF") && TDName.endswith("Ref"));
-}
-
-/// CheckObjCBridgeAttribute - Checks that objc_bridge attribute is
-/// properly applied to a typedef of a pointer to struct/union/class
-static void CheckObjCBridgeAttribute(Sema &S, TypedefDecl *TD) {
-  QualType T = TD->getUnderlyingType();
-  if (!T->isPointerType())
-    return;
-  T = T->getPointeeType();
-  if (T->isStructureType() || T->isUnionType() || T->isClassType())
-    if (RecordDecl *RD = T->getAs<RecordType>()->getDecl())
-      if (RD->hasAttr<ObjCBridgeAttr>() && !isTollFreeBridgeCFRefType(TD))
-        S.Diag(TD->getLocStart(), diag::err_objc_bridge_not_cftype);
-}
-
 TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
                                     TypeSourceInfo *TInfo) {
   assert(D.getIdentifier() && "Wrong callback for declspec without declarator");
@@ -10119,8 +10094,6 @@ TypedefDecl *Sema::ParseTypedefDecl(Scop
     NewTD->setInvalidDecl();
     return NewTD;
   }
-
-  CheckObjCBridgeAttribute(*this, NewTD);
   
   if (D.getDeclSpec().isModulePrivateSpecified()) {
     if (CurContext->isFunctionOrMethod())

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=195066&r1=195065&r2=195066&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Nov 18 19:23:07 2013
@@ -4392,7 +4392,8 @@ static void handleNSBridgedAttr(Sema &S,
 static void handleObjCBridgeAttr(Sema &S, Scope *Sc, Decl *D,
                                 const AttributeList &Attr) {
   if (!isa<RecordDecl>(D)) {
-    S.Diag(D->getLocStart(), diag::err_objc_bridge_attribute);
+    S.Diag(D->getLocStart(), diag::err_objc_bridge_attribute)
+      << S.getLangOpts().CPlusPlus;
     return;
   }
   

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=195066&r1=195065&r2=195066&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Nov 18 19:23:07 2013
@@ -3199,11 +3199,11 @@ static bool CheckObjCBridgeNSCast(Sema &
               if ((CastClass == ExprClass) || (CastClass && ExprClass->isSuperClassOf(CastClass)))
                 return true;
               S.Diag(castExpr->getLocStart(), diag::warn_objc_invalid_bridge)
-                << TDNDecl->getName() << Target->getName() << CastClass->getName();
+                << T << Target->getName() << castType->getPointeeType();
               return true;
             } else {
               S.Diag(castExpr->getLocStart(), diag::warn_objc_invalid_bridge)
-                << TDNDecl->getName() << Target->getName() << castType;
+                << T << Target->getName() << castType;
               return true;
            }
           }
@@ -3243,7 +3243,7 @@ static bool CheckObjCBridgeCFCast(Sema &
               if ((CastClass == ExprClass) || (ExprClass && CastClass->isSuperClassOf(ExprClass)))
                 return true;
               S.Diag(castExpr->getLocStart(), diag::warn_objc_invalid_bridge_to_cf)
-                << ExprClass->getName() << TDNDecl->getName();
+                << castExpr->getType()->getPointeeType() << T;
               S.Diag(TDNDecl->getLocStart(), diag::note_declared_at);
               return true;
             } else {

Modified: cfe/trunk/test/SemaObjC/objcbridge-attribute.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objcbridge-attribute.m?rev=195066&r1=195065&r2=195066&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objcbridge-attribute.m (original)
+++ cfe/trunk/test/SemaObjC/objcbridge-attribute.m Mon Nov 18 19:23:07 2013
@@ -7,28 +7,28 @@ typedef struct __attribute__((objc_bridg
 
 typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
 
-typedef void *  __attribute__ ((objc_bridge(NSURL))) CFURLRef;  // expected-error {{'objc_bridge' attribute must be applied to a struct, C++ class, or union}}
+typedef void *  __attribute__ ((objc_bridge(NSURL))) CFURLRef;  // expected-error {{'objc_bridge' attribute must be applied to a struct or union}}
 
-typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute must be applied to a struct, C++ class, or union}}
+typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute must be applied to a struct or union}}
 
 typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
 
-typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute must be applied to a struct, C++ class, or union}}
+typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute must be applied to a struct or union}}
 
 typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef;
 
-typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute must be applied to a struct, C++ class, or union}};
+typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{'objc_bridge' attribute must be applied to a struct or union}};
 
-typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute must be applied to a struct, C++ class, or union}};
+typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{'objc_bridge' attribute must be applied to a struct or union}};
 
-typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute must be applied to a struct, C++ class, or union}};
+typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{'objc_bridge' attribute must be applied to a struct or union}};
 
 typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;
 typedef XXX *CFUColor2Ref;
 
 @interface I
 {
-   __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute must be applied to a struct, C++ class, or union}};
+   __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute must be applied to a struct or union}};
 }
 @end
 
@@ -55,12 +55,12 @@ typedef CFErrorRef1 CFErrorRef2;
 @class NSString;
 
 void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
-  (void)(NSString *)cf; // expected-warning {{CFErrorRef2 bridges to NSError, not NSString}}
+  (void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
   (void)(NSError *)cf; // okay
   (void)(MyError*)cf; // okay,
   (void)(NSUColor *)cf2; // okay
   (void)(CFErrorRef)ns; // okay
-  (void)(CFErrorRef)str;  // expected-warning {{NSString cannot bridge to CFErrorRef}}
-  (void)(Class)cf; // expected-warning {{CFErrorRef2 bridges to NSError, not 'Class'}}
+  (void)(CFErrorRef)str;  // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
+  (void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}
   (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}}
 }





More information about the cfe-commits mailing list