This is an archive of the discontinued LLVM Phabricator instance.

[clang] Don't make ObjCIvarDecl visible twice when adding them to an implicit ObjCInterfaceDecl
ClosedPublic

Authored by teemperor on Jul 28 2020, 11:30 PM.

Details

Summary

addDecl is making the ivar visible in its primary context. The primary context of the ivar here is
in a 'fragile' ABI the ObjCInterfaceDecl and in a 'non-fragile' ABI the current ObjCImplementationDecl.
The additional call to makeDeclVisibleInContext to make the ivar visible in the ObjCInterfaceDecl
is only necessary in the 'non-fragile' case (as in the 'fragile' case the Decl becomes automatically visible
in the ObjCInterfaceDecl with the addDecl call as thats its primary context). See Sema::ActOnIvar
for where the ivar is put into a different context depending on the ABI.

To put this into an example:

@implementation SomeClass
{
  id ivar1;
}
@end

fragile case:
implicit ObjCInterfaceDecl 'SomeClass'
`- ivar1 (in primary context and will be automatically made visible)
ObjCImplementationDecl 'SomeClass'

non-fragile case:
implicit ObjCInterfaceDecl 'SomeClass'
`-<<<ivar1 not visible here and needs to be manually marked as visible.>>>
ObjCImplementationDecl 'SomeClass'
`- ivar1 (in its primary context and will be automatically made visible here)

Making a Decl visible multiple times in the same context is inefficient and potentially
can lead to crashes. See D84827 for more info and what this is breaking.

Diff Detail

Event Timeline

teemperor requested review of this revision.Jul 28 2020, 11:30 PM
teemperor created this revision.

That code is <2010 code and not sure who's the author is, so just adding Adrian as the reviewer (who already got a similar review)

teemperor updated this revision to Diff 281505.Jul 29 2020, 4:13 AM
teemperor edited the summary of this revision. (Show Details)
  • Preserve the makeDeclVisibleInContext call for non-fragile ABIs.
teemperor edited the summary of this revision. (Show Details)Jul 29 2020, 6:38 AM
aprantl accepted this revision.Jul 31 2020, 5:30 PM
This revision is now accepted and ready to land.Jul 31 2020, 5:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2020, 7:25 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript