gargvaibhav64 updated this revision to Diff 287060. gargvaibhav64 added a comment.
I updated the -triple option to x86_64-pc-windows-msvc (as it was more consistent with current tests). I also updated the path to Unix style in the -I option. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83174/new/ https://reviews.llvm.org/D83174 Files: clang/lib/Serialization/ASTReaderDecl.cpp clang/test/Modules/Inputs/inherit-attribute/a.h clang/test/Modules/Inputs/inherit-attribute/b.h clang/test/Modules/Inputs/inherit-attribute/c.h clang/test/Modules/Inputs/inherit-attribute/module.modulemap clang/test/Modules/inherit-attribute.cpp
Index: clang/test/Modules/inherit-attribute.cpp =================================================================== --- /dev/null +++ clang/test/Modules/inherit-attribute.cpp @@ -0,0 +1,20 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -triple x86_64-pc-windows-msvc -I%S/Inputs/inherit-attribute -fmodules-cache-path=%t \ +// RUN: -fimplicit-module-maps -fmodules-local-submodule-visibility %s -ast-dump-all \ +// RUN: | FileCheck %s + +#include "b.h" +#include "c.h" + +class Foo; + +Foo f; + +// CHECK: CXXRecordDecl {{.*}} imported in b {{.*}} Foo +// CHECK: MSInheritanceAttr {{[^()]*$}} + +// CHECK: CXXRecordDecl {{.*}} prev {{.*}} imported in c {{.*}} Foo +// CHECK: MSInheritanceAttr {{.*}} Inherited {{[^()]*$}} + +// CHECK: CXXRecordDecl {{.*}} <line:9:1, col:7> col:7 referenced class Foo +// CHECK: MSInheritanceAttr {{.*}} Inherited {{[^()]*$}} Index: clang/test/Modules/Inputs/inherit-attribute/module.modulemap =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/inherit-attribute/module.modulemap @@ -0,0 +1,3 @@ +module "b" { header "b.h" } + +module "c" { header "c.h" } Index: clang/test/Modules/Inputs/inherit-attribute/c.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/inherit-attribute/c.h @@ -0,0 +1 @@ +#include "a.h" Index: clang/test/Modules/Inputs/inherit-attribute/b.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/inherit-attribute/b.h @@ -0,0 +1,5 @@ +#include "a.h" + +void bar() { + &Foo::step; +} Index: clang/test/Modules/Inputs/inherit-attribute/a.h =================================================================== --- /dev/null +++ clang/test/Modules/Inputs/inherit-attribute/a.h @@ -0,0 +1,10 @@ +#ifndef FOO +#define FOO + +class Foo { +public: + void step(int v); + Foo(); +}; + +#endif Index: clang/lib/Serialization/ASTReaderDecl.cpp =================================================================== --- clang/lib/Serialization/ASTReaderDecl.cpp +++ clang/lib/Serialization/ASTReaderDecl.cpp @@ -281,6 +281,9 @@ static Decl *getMostRecentDeclImpl(...); static Decl *getMostRecentDecl(Decl *D); + static void mergeInheritableAttributes(ASTReader &Reader, Decl *D, + Decl *Previous); + template <typename DeclT> static void attachPreviousDeclImpl(ASTReader &Reader, Redeclarable<DeclT> *D, Decl *Previous, @@ -3531,6 +3534,19 @@ return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl()); } +void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D, + Decl *Previous) { + InheritableAttr *NewAttr = nullptr; + ASTContext &Context = Reader.getContext(); + const auto *IA = Previous->getAttr<MSInheritanceAttr>(); + + if (IA && !D->hasAttr<MSInheritanceAttr>()) { + NewAttr = cast<InheritableAttr>(IA->clone(Context)); + NewAttr->setInherited(true); + D->addAttr(NewAttr); + } +} + template<typename DeclT> void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, Redeclarable<DeclT> *D, @@ -3689,6 +3705,12 @@ if (auto *TD = dyn_cast<TemplateDecl>(D)) inheritDefaultTemplateArguments(Reader.getContext(), cast<TemplateDecl>(Previous), TD); + + // If any of the declaration in the chain contains an Inheritable attribute, + // it needs to be added to all the declarations in the redeclarable chain. + // FIXME: Only the logic of merging MSInheritableAttr is present, it should + // be extended for all inheritable attributes. + mergeInheritableAttributes(Reader, D, Previous); } template<typename DeclT>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits