[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin closed this revision. a.sidorin added a comment. Closed with https://reviews.llvm.org/rL318776 (forgot Differential Revision, sorry). https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin added inline comments. Comment at: lib/AST/ASTImporter.cpp:2993 + return nullptr; + } + szepet wrote: > nit: As I see these cases typically handled in the way: > > ``` > FrPattern = .; > ToPattern = ..; > if(FrPattern && !ToPattern) > ``` > Just to avoid the nested ifstmt. The logic is a bit more complicated. There are 3 cases: # Both `FromPattern` and `ToPattern` are `nullptr`s. Just continue. # `FromPattern` is non-null and `ToPattern` is null. Return error (`nullptr`). # Both `FromPattern` and `ToPattern` are `nullptr`s. Do the `set...` action. So, it will require nested `if`s or a code like: ``` if (FromPattern && ToPattern) set... if (FromPattern && !ToPattern) return nullptr; ``` Comment at: lib/AST/ASTImporter.cpp:3000 +else + // FIXME: We return a nullptr here but the definition is already created + // and available with lookups. How to fix this?.. szepet wrote: > I dont see the problem with moving these up , collect nad investigate them in > a smallset before the Create function, then adding them to the created > ToUsing decl. It could be done as a follow up patch, dont want to mark it as > a blocking issue. There is a chicken and egg problem: both UsingShadowDecl and UsingDecl reference each other and UsingShadowDecl gets referenced UsingDecl as a ctor argument. If you have a good idea on how to resolve this dependency correctly, please point me. https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin updated this revision to Diff 102679. a.sidorin marked an inline comment as done. a.sidorin added a comment. Herald added a subscriber: kristof.beyls. Add a FIXME. https://reviews.llvm.org/D32751 Files: lib/AST/ASTImporter.cpp test/ASTMerge/namespace/Inputs/namespace1.cpp test/ASTMerge/namespace/Inputs/namespace2.cpp test/ASTMerge/namespace/test.cpp Index: test/ASTMerge/namespace/test.cpp === --- test/ASTMerge/namespace/test.cpp +++ test/ASTMerge/namespace/test.cpp @@ -1,6 +1,17 @@ -// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/namespace1.cpp -// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/namespace2.cpp -// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/namespace1.cpp +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/namespace2.cpp +// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +static_assert(TestAliasName::z == 4); +static_assert(ContainsInline::z == 10); + +void testImport() { + typedef TestUnresolvedTypenameAndValueDecls::Derived Imported; + Imported a; // Successfull instantiation + static_assert(sizeof(Imported::foo) == sizeof(int)); + static_assert(sizeof(TestUnresolvedTypenameAndValueDecls::Derived::NewUnresolvedUsingType) == sizeof(double)); +} + // CHECK: namespace2.cpp:16:17: error: external variable 'z' declared with incompatible types in different translation units ('double' vs. 'float') // CHECK: namespace1.cpp:16:16: note: declared here with type 'float' Index: test/ASTMerge/namespace/Inputs/namespace2.cpp === --- test/ASTMerge/namespace/Inputs/namespace2.cpp +++ test/ASTMerge/namespace/Inputs/namespace2.cpp @@ -15,3 +15,46 @@ namespace N3 { extern double z; } + +namespace Enclosing { +namespace Nested { + const int z = 4; +} +} + +namespace ContainsInline { + inline namespace Inline { +const int z = 10; + } +} + +namespace TestAliasName = Enclosing::Nested; +// NOTE: There is no warning on this alias. +namespace AliasWithSameName = Enclosing::Nested; + +namespace TestUsingDecls { + +namespace A { +void foo(); +} +namespace B { +using A::foo; // <- a UsingDecl creating a UsingShadow +} + +}// end namespace TestUsingDecls + +namespace TestUnresolvedTypenameAndValueDecls { + +template class Base; +template class Derived : public Base { +public: + using typename Base::foo; + using Base::bar; + typedef typename Derived::foo NewUnresolvedUsingType; +}; + +} // end namespace TestUnresolvedTypenameAndValueDecls + +namespace TestUsingNamespace { + using namespace Enclosing; +} Index: test/ASTMerge/namespace/Inputs/namespace1.cpp === --- test/ASTMerge/namespace/Inputs/namespace1.cpp +++ test/ASTMerge/namespace/Inputs/namespace1.cpp @@ -15,3 +15,13 @@ namespace N3 { extern float z; } + +namespace AliasWithSameName = N3; + +namespace TestUnresolvedTypenameAndValueDecls { +template class Base { +public: + typedef T foo; + void bar(); +}; +} Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -58,7 +58,7 @@ QualType VisitExtVectorType(const ExtVectorType *T); QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); QualType VisitFunctionProtoType(const FunctionProtoType *T); -// FIXME: UnresolvedUsingType +QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); QualType VisitParenType(const ParenType *T); QualType VisitTypedefType(const TypedefType *T); QualType VisitTypeOfExprType(const TypeOfExprType *T); @@ -128,8 +128,8 @@ TemplateParameterList *ImportTemplateParameterList( TemplateParameterList *Params); TemplateArgument ImportTemplateArgument(const TemplateArgument &From); -TemplateArgumentLoc ImportTemplateArgumentLoc( -const TemplateArgumentLoc &TALoc, bool &Error); +Optional ImportTemplateArgumentLoc( +const TemplateArgumentLoc &TALoc); bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl &ToArgs); @@ -142,10 +142,12 @@ bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); Decl *VisitDecl(Decl *D); +Decl *VisitEmptyDecl(EmptyDecl *D); Decl *VisitAccessSpecDecl(AccessSpecDecl *D); Decl *VisitStaticAssertDecl(StaticAssertDecl *D); Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); Decl *VisitNamespaceDecl(NamespaceDecl *D); +Decl *VisitNamespaceAliasDecl(NamespaceAli
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin added a comment. Hello Peter, `if (!ToDecl) return nullptr;` is used if original node is always non-null. `if(!ToDecl && FromDecl) return nullptr;` is used if original node can be null. If the imported node is null, the result of import is null as well so such import is OK. `ObjectXY::Create(...Import(FromDecl))` is often used for source locations - as I guess, invalid source location is OK usually. It can also be used if we know that node should already be imported, but usually indicates a potential error. https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
szepet added a comment. Some nits added, other than these it looks good to me. Thank you! Just more one question, I can see 3 different cases how the import returns are handled: - if(!ToDecl) return nullptr; - if(!ToDecl && FromDecl) return nullptr; - no handling: ObjectXY::Create(...Import(FromDecl)) My question is the following: which cases require a check and which decls can be imported without checking the return value of the **import **function? (Yepp, it could be asked in more general about the Importer, since things like this would be great to follow a convention. I have found some cases where it was not obivous to me which way to check. ) Comment at: lib/AST/ASTImporter.cpp:2993 + return nullptr; + } + nit: As I see these cases typically handled in the way: ``` FrPattern = .; ToPattern = ..; if(FrPattern && !ToPattern) ``` Just to avoid the nested ifstmt. Comment at: lib/AST/ASTImporter.cpp:3000 +else + // FIXME: We return a nullptr here but the definition is already created + // and available with lookups. How to fix this?.. I dont see the problem with moving these up , collect nad investigate them in a smallset before the Create function, then adding them to the created ToUsing decl. It could be done as a follow up patch, dont want to mark it as a blocking issue. Comment at: lib/AST/ASTImporter.cpp:3042 + return nullptr; + } + the same nit as above Comment at: lib/AST/ASTImporter.cpp:3043 + } + + LexicalDC->addDeclInternal(ToShadow); Does not this causes the same FIXME problem as above? https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin added inline comments. Comment at: lib/AST/ASTImporter.cpp:1311 + EmptyDecl *ToD = EmptyDecl::Create(Importer.getToContext(), DC, Loc); + ToD->setLexicalDeclContext(LexicalDC); + LexicalDC->addDeclInternal(ToD); xazax.hun wrote: > Don't we need an Importer.Imported call here? It's done a level upper in `ASTImporter::ImportDecl()` but I think it's worth it to add an explicit call. Comment at: lib/AST/ASTImporter.cpp:1464 + + NamespaceDecl *TargetDecl = cast( +Importer.Import(D->getNamespace())); szepet wrote: > Since the Import can result nullptr (which is checked 2 lines below) this > should be a cast_or_null as I see. Nice spot, thank you! https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin updated this revision to Diff 99669. a.sidorin added a comment. Removed accidentally duplicated comment. https://reviews.llvm.org/D32751 Files: lib/AST/ASTImporter.cpp test/ASTMerge/namespace/Inputs/namespace1.cpp test/ASTMerge/namespace/Inputs/namespace2.cpp test/ASTMerge/namespace/test.cpp Index: test/ASTMerge/namespace/test.cpp === --- test/ASTMerge/namespace/test.cpp +++ test/ASTMerge/namespace/test.cpp @@ -1,6 +1,17 @@ -// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/namespace1.cpp -// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/namespace2.cpp -// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/namespace1.cpp +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/namespace2.cpp +// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +static_assert(TestAliasName::z == 4); +static_assert(ContainsInline::z == 10); + +void testImport() { + typedef TestUnresolvedTypenameAndValueDecls::Derived Imported; + Imported a; // Successfull instantiation + static_assert(sizeof(Imported::foo) == sizeof(int)); + static_assert(sizeof(TestUnresolvedTypenameAndValueDecls::Derived::NewUnresolvedUsingType) == sizeof(double)); +} + // CHECK: namespace2.cpp:16:17: error: external variable 'z' declared with incompatible types in different translation units ('double' vs. 'float') // CHECK: namespace1.cpp:16:16: note: declared here with type 'float' Index: test/ASTMerge/namespace/Inputs/namespace2.cpp === --- test/ASTMerge/namespace/Inputs/namespace2.cpp +++ test/ASTMerge/namespace/Inputs/namespace2.cpp @@ -15,3 +15,46 @@ namespace N3 { extern double z; } + +namespace Enclosing { +namespace Nested { + const int z = 4; +} +} + +namespace ContainsInline { + inline namespace Inline { +const int z = 10; + } +} + +namespace TestAliasName = Enclosing::Nested; +// NOTE: There is no warning on this alias. +namespace AliasWithSameName = Enclosing::Nested; + +namespace TestUsingDecls { + +namespace A { +void foo(); +} +namespace B { +using A::foo; // <- a UsingDecl creating a UsingShadow +} + +}// end namespace TestUsingDecls + +namespace TestUnresolvedTypenameAndValueDecls { + +template class Base; +template class Derived : public Base { +public: + using typename Base::foo; + using Base::bar; + typedef typename Derived::foo NewUnresolvedUsingType; +}; + +} // end namespace TestUnresolvedTypenameAndValueDecls + +namespace TestUsingNamespace { + using namespace Enclosing; +} Index: test/ASTMerge/namespace/Inputs/namespace1.cpp === --- test/ASTMerge/namespace/Inputs/namespace1.cpp +++ test/ASTMerge/namespace/Inputs/namespace1.cpp @@ -15,3 +15,13 @@ namespace N3 { extern float z; } + +namespace AliasWithSameName = N3; + +namespace TestUnresolvedTypenameAndValueDecls { +template class Base { +public: + typedef T foo; + void bar(); +}; +} Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -58,7 +58,7 @@ QualType VisitExtVectorType(const ExtVectorType *T); QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); QualType VisitFunctionProtoType(const FunctionProtoType *T); -// FIXME: UnresolvedUsingType +QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); QualType VisitParenType(const ParenType *T); QualType VisitTypedefType(const TypedefType *T); QualType VisitTypeOfExprType(const TypeOfExprType *T); @@ -128,8 +128,8 @@ TemplateParameterList *ImportTemplateParameterList( TemplateParameterList *Params); TemplateArgument ImportTemplateArgument(const TemplateArgument &From); -TemplateArgumentLoc ImportTemplateArgumentLoc( -const TemplateArgumentLoc &TALoc, bool &Error); +Optional ImportTemplateArgumentLoc( +const TemplateArgumentLoc &TALoc); bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl &ToArgs); @@ -142,10 +142,12 @@ bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); Decl *VisitDecl(Decl *D); +Decl *VisitEmptyDecl(EmptyDecl *D); Decl *VisitAccessSpecDecl(AccessSpecDecl *D); Decl *VisitStaticAssertDecl(StaticAssertDecl *D); Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); Decl *VisitNamespaceDecl(NamespaceDecl *D); +Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); Decl *VisitTypedefNameDecl(TypedefNameDecl
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin updated this revision to Diff 99668. a.sidorin added a comment. Replaced cast<> with cast_or_null<>. https://reviews.llvm.org/D32751 Files: lib/AST/ASTImporter.cpp test/ASTMerge/namespace/Inputs/namespace1.cpp test/ASTMerge/namespace/Inputs/namespace2.cpp test/ASTMerge/namespace/test.cpp Index: test/ASTMerge/namespace/test.cpp === --- test/ASTMerge/namespace/test.cpp +++ test/ASTMerge/namespace/test.cpp @@ -1,6 +1,17 @@ -// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/namespace1.cpp -// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/namespace2.cpp -// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/namespace1.cpp +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/namespace2.cpp +// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +static_assert(TestAliasName::z == 4); +static_assert(ContainsInline::z == 10); + +void testImport() { + typedef TestUnresolvedTypenameAndValueDecls::Derived Imported; + Imported a; // Successfull instantiation + static_assert(sizeof(Imported::foo) == sizeof(int)); + static_assert(sizeof(TestUnresolvedTypenameAndValueDecls::Derived::NewUnresolvedUsingType) == sizeof(double)); +} + // CHECK: namespace2.cpp:16:17: error: external variable 'z' declared with incompatible types in different translation units ('double' vs. 'float') // CHECK: namespace1.cpp:16:16: note: declared here with type 'float' Index: test/ASTMerge/namespace/Inputs/namespace2.cpp === --- test/ASTMerge/namespace/Inputs/namespace2.cpp +++ test/ASTMerge/namespace/Inputs/namespace2.cpp @@ -15,3 +15,46 @@ namespace N3 { extern double z; } + +namespace Enclosing { +namespace Nested { + const int z = 4; +} +} + +namespace ContainsInline { + inline namespace Inline { +const int z = 10; + } +} + +namespace TestAliasName = Enclosing::Nested; +// NOTE: There is no warning on this alias. +namespace AliasWithSameName = Enclosing::Nested; + +namespace TestUsingDecls { + +namespace A { +void foo(); +} +namespace B { +using A::foo; // <- a UsingDecl creating a UsingShadow +} + +}// end namespace TestUsingDecls + +namespace TestUnresolvedTypenameAndValueDecls { + +template class Base; +template class Derived : public Base { +public: + using typename Base::foo; + using Base::bar; + typedef typename Derived::foo NewUnresolvedUsingType; +}; + +} // end namespace TestUnresolvedTypenameAndValueDecls + +namespace TestUsingNamespace { + using namespace Enclosing; +} Index: test/ASTMerge/namespace/Inputs/namespace1.cpp === --- test/ASTMerge/namespace/Inputs/namespace1.cpp +++ test/ASTMerge/namespace/Inputs/namespace1.cpp @@ -15,3 +15,13 @@ namespace N3 { extern float z; } + +namespace AliasWithSameName = N3; + +namespace TestUnresolvedTypenameAndValueDecls { +template class Base { +public: + typedef T foo; + void bar(); +}; +} Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -58,7 +58,7 @@ QualType VisitExtVectorType(const ExtVectorType *T); QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); QualType VisitFunctionProtoType(const FunctionProtoType *T); -// FIXME: UnresolvedUsingType +QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); QualType VisitParenType(const ParenType *T); QualType VisitTypedefType(const TypedefType *T); QualType VisitTypeOfExprType(const TypeOfExprType *T); @@ -128,8 +128,8 @@ TemplateParameterList *ImportTemplateParameterList( TemplateParameterList *Params); TemplateArgument ImportTemplateArgument(const TemplateArgument &From); -TemplateArgumentLoc ImportTemplateArgumentLoc( -const TemplateArgumentLoc &TALoc, bool &Error); +Optional ImportTemplateArgumentLoc( +const TemplateArgumentLoc &TALoc); bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl &ToArgs); @@ -142,10 +142,12 @@ bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); Decl *VisitDecl(Decl *D); +Decl *VisitEmptyDecl(EmptyDecl *D); Decl *VisitAccessSpecDecl(AccessSpecDecl *D); Decl *VisitStaticAssertDecl(StaticAssertDecl *D); Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); Decl *VisitNamespaceDecl(NamespaceDecl *D); +Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); Decl *VisitTypedefNameDecl(TypedefNameDecl *D,
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
szepet added inline comments. Comment at: lib/AST/ASTImporter.cpp:1464 + + NamespaceDecl *TargetDecl = cast( +Importer.Import(D->getNamespace())); Since the Import can result nullptr (which is checked 2 lines below) this should be a cast_or_null as I see. https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
xazax.hun accepted this revision. xazax.hun added a reviewer: szepet. xazax.hun added a comment. This revision is now accepted and ready to land. LGTM! Adding Peter as a reviewer, as he is more experienced with the ASTImporter than me. https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin updated this revision to Diff 98441. a.sidorin added a reviewer: karkhaz. a.sidorin added a comment. Address review comments; add the context. https://reviews.llvm.org/D32751 Files: lib/AST/ASTImporter.cpp test/ASTMerge/namespace/Inputs/namespace1.cpp test/ASTMerge/namespace/Inputs/namespace2.cpp test/ASTMerge/namespace/test.cpp Index: test/ASTMerge/namespace/test.cpp === --- test/ASTMerge/namespace/test.cpp +++ test/ASTMerge/namespace/test.cpp @@ -1,6 +1,17 @@ -// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/namespace1.cpp -// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/namespace2.cpp -// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/namespace1.cpp +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/namespace2.cpp +// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +static_assert(TestAliasName::z == 4); +static_assert(ContainsInline::z == 10); + +void testImport() { + typedef TestUnresolvedTypenameAndValueDecls::Derived Imported; + Imported a; // Successfull instantiation + static_assert(sizeof(Imported::foo) == sizeof(int)); + static_assert(sizeof(TestUnresolvedTypenameAndValueDecls::Derived::NewUnresolvedUsingType) == sizeof(double)); +} + // CHECK: namespace2.cpp:16:17: error: external variable 'z' declared with incompatible types in different translation units ('double' vs. 'float') // CHECK: namespace1.cpp:16:16: note: declared here with type 'float' Index: test/ASTMerge/namespace/Inputs/namespace2.cpp === --- test/ASTMerge/namespace/Inputs/namespace2.cpp +++ test/ASTMerge/namespace/Inputs/namespace2.cpp @@ -15,3 +15,46 @@ namespace N3 { extern double z; } + +namespace Enclosing { +namespace Nested { + const int z = 4; +} +} + +namespace ContainsInline { + inline namespace Inline { +const int z = 10; + } +} + +namespace TestAliasName = Enclosing::Nested; +// NOTE: There is no warning on this alias. +namespace AliasWithSameName = Enclosing::Nested; + +namespace TestUsingDecls { + +namespace A { +void foo(); +} +namespace B { +using A::foo; // <- a UsingDecl creating a UsingShadow +} + +}// end namespace TestUsingDecls + +namespace TestUnresolvedTypenameAndValueDecls { + +template class Base; +template class Derived : public Base { +public: + using typename Base::foo; + using Base::bar; + typedef typename Derived::foo NewUnresolvedUsingType; +}; + +} // end namespace TestUnresolvedTypenameAndValueDecls + +namespace TestUsingNamespace { + using namespace Enclosing; +} Index: test/ASTMerge/namespace/Inputs/namespace1.cpp === --- test/ASTMerge/namespace/Inputs/namespace1.cpp +++ test/ASTMerge/namespace/Inputs/namespace1.cpp @@ -15,3 +15,13 @@ namespace N3 { extern float z; } + +namespace AliasWithSameName = N3; + +namespace TestUnresolvedTypenameAndValueDecls { +template class Base { +public: + typedef T foo; + void bar(); +}; +} Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -58,7 +58,7 @@ QualType VisitExtVectorType(const ExtVectorType *T); QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); QualType VisitFunctionProtoType(const FunctionProtoType *T); -// FIXME: UnresolvedUsingType +QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); QualType VisitParenType(const ParenType *T); QualType VisitTypedefType(const TypedefType *T); QualType VisitTypeOfExprType(const TypeOfExprType *T); @@ -128,8 +128,8 @@ TemplateParameterList *ImportTemplateParameterList( TemplateParameterList *Params); TemplateArgument ImportTemplateArgument(const TemplateArgument &From); -TemplateArgumentLoc ImportTemplateArgumentLoc( -const TemplateArgumentLoc &TALoc, bool &Error); +Optional ImportTemplateArgumentLoc( +const TemplateArgumentLoc &TALoc); bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl &ToArgs); @@ -142,10 +142,12 @@ bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); Decl *VisitDecl(Decl *D); +Decl *VisitEmptyDecl(EmptyDecl *D); Decl *VisitAccessSpecDecl(AccessSpecDecl *D); Decl *VisitStaticAssertDecl(StaticAssertDecl *D); Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); Decl *VisitNamespaceDecl(NamespaceDecl *D); +Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); Decl
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
xazax.hun added a comment. Looks good for me, I only have a few questions. Could you reupload the diff with contexts? It might make the review easier for others. Comment at: lib/AST/ASTImporter.cpp:1311 + EmptyDecl *ToD = EmptyDecl::Create(Importer.getToContext(), DC, Loc); + ToD->setLexicalDeclContext(LexicalDC); + LexicalDC->addDeclInternal(ToD); Don't we need an Importer.Imported call here? Comment at: lib/AST/ASTImporter.cpp:1461 + + // NOTE: No any conflict resolution is done for namespace aliases. + Minor nit: do we need the any in this sentence? https://reviews.llvm.org/D32751 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D32751: [ASTImporter] Support new kinds of declarations (mostly Using*)
a.sidorin created this revision. Herald added subscribers: rengolin, aemerson. Support new AST nodes: - UnresolvedUsingType - EmptyDecl - NamespaceAliasDecl - UsingDecl - UsingShadowDecl - UsingDirectiveDecl - UnresolvedUsingValueDecl - UnresolvedUsingTypenameDecl Refactor error handling in ImportTemplateArgumentLoc() method. Add a test for inline namespaces. Please take a look at FIXMEs I left in some places where I'm not sure that I have chosen a correct solution. Also, I have some doubts for duplicating NamespaceAliasDecls. I found presence of such decls harmless but maybe I'm not correct here. I left NOTE comments both in the patch and in the tests for it. https://reviews.llvm.org/D32751 Files: lib/AST/ASTImporter.cpp test/ASTMerge/namespace/Inputs/namespace1.cpp test/ASTMerge/namespace/Inputs/namespace2.cpp test/ASTMerge/namespace/test.cpp Index: test/ASTMerge/namespace/test.cpp === --- test/ASTMerge/namespace/test.cpp +++ test/ASTMerge/namespace/test.cpp @@ -1,6 +1,17 @@ -// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/namespace1.cpp -// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/namespace2.cpp -// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/namespace1.cpp +// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/namespace2.cpp +// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s + +static_assert(TestAliasName::z == 4); +static_assert(ContainsInline::z == 10); + +void testImport() { + typedef TestUnresolvedTypenameAndValueDecls::Derived Imported; + Imported a; // Successfull instantiation + static_assert(sizeof(Imported::foo) == sizeof(int)); + static_assert(sizeof(TestUnresolvedTypenameAndValueDecls::Derived::NewUnresolvedUsingType) == sizeof(double)); +} + // CHECK: namespace2.cpp:16:17: error: external variable 'z' declared with incompatible types in different translation units ('double' vs. 'float') // CHECK: namespace1.cpp:16:16: note: declared here with type 'float' Index: test/ASTMerge/namespace/Inputs/namespace2.cpp === --- test/ASTMerge/namespace/Inputs/namespace2.cpp +++ test/ASTMerge/namespace/Inputs/namespace2.cpp @@ -15,3 +15,46 @@ namespace N3 { extern double z; } + +namespace Enclosing { +namespace Nested { + const int z = 4; +} +} + +namespace ContainsInline { + inline namespace Inline { +const int z = 10; + } +} + +namespace TestAliasName = Enclosing::Nested; +// NOTE: There is no warning on this alias. +namespace AliasWithSameName = Enclosing::Nested; + +namespace TestUsingDecls { + +namespace A { +void foo(); +} +namespace B { +using A::foo; // <- a UsingDecl creating a UsingShadow +} + +}// end namespace TestUsingDecls + +namespace TestUnresolvedTypenameAndValueDecls { + +template class Base; +template class Derived : public Base { +public: + using typename Base::foo; + using Base::bar; + typedef typename Derived::foo NewUnresolvedUsingType; +}; + +} // end namespace TestUnresolvedTypenameAndValueDecls + +namespace TestUsingNamespace { + using namespace Enclosing; +} Index: test/ASTMerge/namespace/Inputs/namespace1.cpp === --- test/ASTMerge/namespace/Inputs/namespace1.cpp +++ test/ASTMerge/namespace/Inputs/namespace1.cpp @@ -15,3 +15,13 @@ namespace N3 { extern float z; } + +namespace AliasWithSameName = N3; + +namespace TestUnresolvedTypenameAndValueDecls { +template class Base { +public: + typedef T foo; + void bar(); +}; +} Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -58,7 +58,7 @@ QualType VisitExtVectorType(const ExtVectorType *T); QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); QualType VisitFunctionProtoType(const FunctionProtoType *T); -// FIXME: UnresolvedUsingType +QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); QualType VisitParenType(const ParenType *T); QualType VisitTypedefType(const TypedefType *T); QualType VisitTypeOfExprType(const TypeOfExprType *T); @@ -128,8 +128,8 @@ TemplateParameterList *ImportTemplateParameterList( TemplateParameterList *Params); TemplateArgument ImportTemplateArgument(const TemplateArgument &From); -TemplateArgumentLoc ImportTemplateArgumentLoc( -const TemplateArgumentLoc &TALoc, bool &Error); +Optional ImportTemplateArgumentLoc( +const TemplateArgumentLoc &TALoc); bool ImportTemplateArguments(const TemplateArgument *FromArgs, unsigned NumFromArgs, SmallVectorImpl &ToArgs); @@ -1