This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by erik.pilkington on Feb 12 2019, 3:22 PM.

Details

Summary

We ran into some source breaking changes to do with the attribute reordering changes that recently landed. The problem is that the order that objc_designated_initializer and objc_method_family are processed matters, because objc_method_family can make a method an init method, which is a prerequisite for objc_designated_initializer. When the attribute order flipped, the arrangement of these attributes that lead to an error and the arrangement that worked fine also flipped. This patch fixes this by delaying the check until both attributes have been processed.

rdar://47829358

Thanks!
Erik

Diff Detail

Repository
rC Clang

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2019, 3:22 PM
aaron.ballman added inline comments.Feb 13 2019, 7:16 AM
clang/lib/Sema/SemaDeclAttr.cpp
5252 ↗(On Diff #186551)

Please don't use auto here.

7258–7267 ↗(On Diff #186551)

Do you also have to handle redeclaration merging, or is that not a thing for ObjC method declarations?

I'm wondering if this is better handled with the mergeFooAttr() pattern from Sema::mergeDeclAttribute()?

erik.pilkington marked an inline comment as done.

Remove an auto.

clang/lib/Sema/SemaDeclAttr.cpp
7258–7267 ↗(On Diff #186551)

You mean delaying the check until we see the method implementation? It seems like that would only enable the following:

@interface X
-(instancetype)meth __attribute__((objc_designated_initializer));
@end
@implementation X
-(instancetype)meth __attribute__((objc_method_family(init))) {}
@end

We never supported this, so there isn't any regression here. I don't even think that this makes sense, the objc_method_family attribute should really go in the @interface. It also means that we'd only diagnose this in the TU that contains the @implementation.

aaron.ballman accepted this revision.Feb 13 2019, 11:57 AM

LGTM with a testing request.

clang/test/SemaObjC/attr-designated-init.m
433–438 ↗(On Diff #186712)

For coverage purposes, can you add these tests as well?

- (instancetype)baz
    __attribute__((objc_designated_initializer, objc_method_family(init)))
- (instancetype)quux
    __attribute__((objc_method_family(init), objc_designated_initializer))
This revision is now accepted and ready to land.Feb 13 2019, 11:57 AM
This revision was automatically updated to reflect the committed changes.