[llvm-branch-commits] [cfe-branch] r354015 - Merging r353976:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Feb 14 02:47:35 PST 2019


Author: hans
Date: Thu Feb 14 02:47:35 2019
New Revision: 354015

URL: http://llvm.org/viewvc/llvm-project?rev=354015&view=rev
Log:
Merging r353976:
------------------------------------------------------------------------
r353976 | epilk | 2019-02-13 21:32:37 +0100 (Wed, 13 Feb 2019) | 11 lines

[Sema] Delay checking whether objc_designated_initializer is being applied to an init method

This fixes a regression that was caused by r335084, which reversed
the order that attributes are applied. objc_method_family can change
whether a method is an init method, so the order that these
attributes are applied matters. The commit fixes this by delaying the
init check until after all attributes have been applied.

rdar://47829358

Differential revision: https://reviews.llvm.org/D58152
------------------------------------------------------------------------

Modified:
    cfe/branches/release_80/   (props changed)
    cfe/branches/release_80/include/clang/Basic/Attr.td
    cfe/branches/release_80/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/branches/release_80/lib/Sema/SemaDeclAttr.cpp
    cfe/branches/release_80/test/Misc/pragma-attribute-supported-attributes-list.test
    cfe/branches/release_80/test/SemaObjC/attr-designated-init.m

Propchange: cfe/branches/release_80/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Feb 14 02:47:35 2019
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:351334,351340,351344,351360,351457,351459,351531,351579-351580,352040,352079,352099,352102,352105,352156,352221-352222,352229,352307,352323,352463,352539,352610,352672,352822,353142,353393,353402,353411,353431,353493,353495,353656
+/cfe/trunk:351334,351340,351344,351360,351457,351459,351531,351579-351580,352040,352079,352099,352102,352105,352156,352221-352222,352229,352307,352323,352463,352539,352610,352672,352822,353142,353393,353402,353411,353431,353493,353495,353656,353976
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_80/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_80/include/clang/Basic/Attr.td?rev=354015&r1=354014&r2=354015&view=diff
==============================================================================
--- cfe/branches/release_80/include/clang/Basic/Attr.td (original)
+++ cfe/branches/release_80/include/clang/Basic/Attr.td Thu Feb 14 02:47:35 2019
@@ -103,13 +103,6 @@ def ObjCInstanceMethod : SubsetSubject<O
                                        [{S->isInstanceMethod()}],
                                        "Objective-C instance methods">;
 
-def ObjCInterfaceDeclInitMethod : SubsetSubject<ObjCMethod,
-                               [{S->getMethodFamily() == OMF_init &&
-                                 (isa<ObjCInterfaceDecl>(S->getDeclContext()) ||
-                                  (isa<ObjCCategoryDecl>(S->getDeclContext()) &&
-            cast<ObjCCategoryDecl>(S->getDeclContext())->IsClassExtension()))}],
-            "init methods of interface or class extension declarations">;
-
 def Struct : SubsetSubject<Record,
                            [{!S->isUnion()}], "structs">;
 
@@ -1762,7 +1755,7 @@ def ObjCExplicitProtocolImpl : Inheritab
 
 def ObjCDesignatedInitializer : Attr {
   let Spellings = [Clang<"objc_designated_initializer">];
-  let Subjects = SubjectList<[ObjCInterfaceDeclInitMethod], ErrorDiag>;
+  let Subjects = SubjectList<[ObjCMethod], ErrorDiag>;
   let Documentation = [Undocumented];
 }
 

Modified: cfe/branches/release_80/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_80/include/clang/Basic/DiagnosticSemaKinds.td?rev=354015&r1=354014&r2=354015&view=diff
==============================================================================
--- cfe/branches/release_80/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/branches/release_80/include/clang/Basic/DiagnosticSemaKinds.td Thu Feb 14 02:47:35 2019
@@ -3460,6 +3460,9 @@ def warn_objc_secondary_init_missing_ini
 def warn_objc_implementation_missing_designated_init_override : Warning<
   "method override for the designated initializer of the superclass %objcinstance0 not found">,
   InGroup<ObjCDesignatedInit>;
+def err_designated_init_attr_non_init : Error<
+  "'objc_designated_initializer' attribute only applies to init methods "
+  "of interface or class extension declarations">;
 
 // objc_bridge attribute diagnostics.
 def err_objc_attr_not_id : Error<

Modified: cfe/branches/release_80/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_80/lib/Sema/SemaDeclAttr.cpp?rev=354015&r1=354014&r2=354015&view=diff
==============================================================================
--- cfe/branches/release_80/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/branches/release_80/lib/Sema/SemaDeclAttr.cpp Thu Feb 14 02:47:35 2019
@@ -5116,11 +5116,22 @@ static void handleObjCBridgeRelatedAttr(
 
 static void handleObjCDesignatedInitializer(Sema &S, Decl *D,
                                             const ParsedAttr &AL) {
+  DeclContext *Ctx = D->getDeclContext();
+
+  // This attribute can only be applied to methods in interfaces or class
+  // extensions.
+  if (!isa<ObjCInterfaceDecl>(Ctx) &&
+      !(isa<ObjCCategoryDecl>(Ctx) &&
+        cast<ObjCCategoryDecl>(Ctx)->IsClassExtension())) {
+    S.Diag(D->getLocation(), diag::err_designated_init_attr_non_init);
+    return;
+  }
+
   ObjCInterfaceDecl *IFace;
-  if (auto *CatDecl = dyn_cast<ObjCCategoryDecl>(D->getDeclContext()))
+  if (auto *CatDecl = dyn_cast<ObjCCategoryDecl>(Ctx))
     IFace = CatDecl->getClassInterface();
   else
-    IFace = cast<ObjCInterfaceDecl>(D->getDeclContext());
+    IFace = cast<ObjCInterfaceDecl>(Ctx);
 
   if (!IFace)
     return;
@@ -7067,6 +7078,17 @@ void Sema::ProcessDeclAttributeList(Scop
       }
     }
   }
+
+  // Do this check after processing D's attributes because the attribute
+  // objc_method_family can change whether the given method is in the init
+  // family, and it can be applied after objc_designated_initializer. This is a
+  // bit of a hack, but we need it to be compatible with versions of clang that
+  // processed the attribute list in the wrong order.
+  if (D->hasAttr<ObjCDesignatedInitializerAttr>() &&
+      cast<ObjCMethodDecl>(D)->getMethodFamily() != OMF_init) {
+    Diag(D->getLocation(), diag::err_designated_init_attr_non_init);
+    D->dropAttr<ObjCDesignatedInitializerAttr>();
+  }
 }
 
 // Helper for delayed processing TransparentUnion attribute.

Modified: cfe/branches/release_80/test/Misc/pragma-attribute-supported-attributes-list.test
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_80/test/Misc/pragma-attribute-supported-attributes-list.test?rev=354015&r1=354014&r2=354015&view=diff
==============================================================================
--- cfe/branches/release_80/test/Misc/pragma-attribute-supported-attributes-list.test (original)
+++ cfe/branches/release_80/test/Misc/pragma-attribute-supported-attributes-list.test Thu Feb 14 02:47:35 2019
@@ -94,6 +94,7 @@
 // CHECK-NEXT: ObjCBridge (SubjectMatchRule_record, SubjectMatchRule_type_alias)
 // CHECK-NEXT: ObjCBridgeMutable (SubjectMatchRule_record)
 // CHECK-NEXT: ObjCBridgeRelated (SubjectMatchRule_record)
+// CHECK-NEXT: ObjCDesignatedInitializer (SubjectMatchRule_objc_method)
 // CHECK-NEXT: ObjCException (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: ObjCExplicitProtocolImpl (SubjectMatchRule_objc_protocol)
 // CHECK-NEXT: ObjCExternallyRetained (SubjectMatchRule_variable_not_is_parameter, SubjectMatchRule_function, SubjectMatchRule_block, SubjectMatchRule_objc_method)

Modified: cfe/branches/release_80/test/SemaObjC/attr-designated-init.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_80/test/SemaObjC/attr-designated-init.m?rev=354015&r1=354014&r2=354015&view=diff
==============================================================================
--- cfe/branches/release_80/test/SemaObjC/attr-designated-init.m (original)
+++ cfe/branches/release_80/test/SemaObjC/attr-designated-init.m Thu Feb 14 02:47:35 2019
@@ -3,7 +3,7 @@
 #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
 #define NS_UNAVAILABLE __attribute__((unavailable))
 
-void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
+void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{'objc_designated_initializer' attribute only applies to Objective-C methods}}
 
 @protocol P1
 -(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}}
@@ -428,3 +428,16 @@ __attribute__((objc_root_class))
 @interface CategoryForMissingInterface(Cat) // expected-error{{cannot find interface declaration}}
 - (instancetype)init NS_DESIGNATED_INITIALIZER; // expected-error{{only applies to init methods of interface or class extension declarations}}
 @end
+
+ at interface TwoAttrs
+-(instancetype)foo
+    __attribute__((objc_designated_initializer))
+    __attribute__((objc_method_family(init)));
+-(instancetype)bar
+    __attribute__((objc_method_family(init)))
+    __attribute__((objc_designated_initializer));
+-(instancetype)baz
+  __attribute__((objc_designated_initializer, objc_method_family(init)));
+-(instancetype)quux
+  __attribute__((objc_method_family(init), objc_designated_initializer));
+ at end




More information about the llvm-branch-commits mailing list