Ensure that InheritedAttrs are properly inherited along a redeclaration

chain for ObjCInterfaceDecls.

Only one such declaration can actually have attributes (the definition,
if any), but generally we assume that we can look for InheritedAttrs on
the most recent declaration.
This commit is contained in:
Richard Smith 2020-10-12 19:17:50 -07:00
parent 84cc39c329
commit e2d4174e9c
2 changed files with 19 additions and 0 deletions

View file

@ -1066,6 +1066,11 @@ Decl *Sema::ActOnStartClassInterface(
ProcessDeclAttributeList(TUScope, IDecl, AttrList);
AddPragmaAttributes(TUScope, IDecl);
// Merge attributes from previous declarations.
if (PrevIDecl)
mergeDeclAttributes(IDecl, PrevIDecl);
PushOnScopeChains(IDecl, TUScope);
// Start the definition of this class. If we're in a redefinition case, there
@ -3125,6 +3130,9 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
IdentLocs[i]);
IDecl->setAtEndRange(IdentLocs[i]);
if (PrevIDecl)
mergeDeclAttributes(IDecl, PrevIDecl);
PushOnScopeChains(IDecl, TUScope);
CheckObjCDeclScope(IDecl);
DeclsInGroup.push_back(IDecl);

View file

@ -22,3 +22,14 @@ __attribute__((availability(macosx,introduced=10.6)))
@implementation WeakClass2(YourCategory) @end
// CHECK-10_4: @"OBJC_CLASS_$_WeakClass3" = extern_weak global
// CHECK-10_5: @"OBJC_CLASS_$_WeakClass3" = extern_weak global
// CHECK-10_6: @"OBJC_CLASS_$_WeakClass3" = external global
__attribute__((availability(macosx,introduced=10.6)))
@interface WeakClass3 @end
@class WeakClass3;
@implementation WeakClass3(MyCategory) @end
@implementation WeakClass3(YourCategory) @end