diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2228,6 +2228,9 @@ ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); if (!BeginLocOrErr) return BeginLocOrErr.takeError(); + ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); + if (!RBraceLocOrErr) + return RBraceLocOrErr.takeError(); // Create the "to" namespace, if needed. NamespaceDecl *ToNamespace = MergeWithNamespace; @@ -2237,6 +2240,7 @@ *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), /*PrevDecl=*/nullptr)) return ToNamespace; + ToNamespace->setRBraceLoc(*RBraceLocOrErr); ToNamespace->setLexicalDeclContext(LexicalDC); LexicalDC->addDeclInternal(ToNamespace); @@ -2545,9 +2549,10 @@ SourceLocation ToBeginLoc; NestedNameSpecifierLoc ToQualifierLoc; QualType ToIntegerType; - if (auto Imp = importSeq( - D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) - std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; + SourceRange ToBraceRange; + if (auto Imp = importSeq(D->getBeginLoc(), D->getQualifierLoc(), + D->getIntegerType(), D->getBraceRange())) + std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType, ToBraceRange) = *Imp; else return Imp.takeError(); @@ -2561,6 +2566,7 @@ D2->setQualifierInfo(ToQualifierLoc); D2->setIntegerType(ToIntegerType); + D2->setBraceRange(ToBraceRange); D2->setAccess(D->getAccess()); D2->setLexicalDeclContext(LexicalDC); LexicalDC->addDeclInternal(D2); @@ -2795,6 +2801,10 @@ LexicalDC->addDeclInternal(D2); } + if (auto BraceRangeOrErr = import(D->getBraceRange())) + D2->setBraceRange(*BraceRangeOrErr); + else + return BraceRangeOrErr.takeError(); if (auto QualifierLocOrErr = import(D->getQualifierLoc())) D2->setQualifierInfo(*QualifierLocOrErr); else @@ -5295,6 +5305,11 @@ LexicalDC->addDeclInternal(D2); } + if (auto BraceRangeOrErr = import(D->getBraceRange())) + D2->setBraceRange(*BraceRangeOrErr); + else + return BraceRangeOrErr.takeError(); + // Import the qualifier, if any. if (auto LocOrErr = import(D->getQualifierLoc())) D2->setQualifierInfo(*LocOrErr); @@ -6293,7 +6308,8 @@ TemplateArgumentListInfo *ToResInfo = nullptr; if (E->hasExplicitTemplateArgs()) { if (Error Err = - ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) + ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), + E->template_arguments(), ToTAInfo)) return std::move(Err); ToResInfo = &ToTAInfo; } @@ -7369,20 +7385,19 @@ ExpectedStmt ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { - auto Imp = importSeq( - E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), - E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); + auto Imp = importSeq(E->getQualifierLoc(), E->getTemplateKeywordLoc(), + E->getDeclName(), E->getNameInfo().getLoc(), + E->getLAngleLoc(), E->getRAngleLoc()); if (!Imp) return Imp.takeError(); NestedNameSpecifierLoc ToQualifierLoc; - SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; + SourceLocation ToTemplateKeywordLoc, ToNameLoc, ToLAngleLoc, ToRAngleLoc; DeclarationName ToDeclName; - std::tie( - ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, - ToLAngleLoc, ToRAngleLoc) = *Imp; + std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToNameLoc, + ToLAngleLoc, ToRAngleLoc) = *Imp; - DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); + DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) return std::move(Err); @@ -7447,7 +7462,7 @@ else return ToDOrErr.takeError(); - if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { + if (E->hasExplicitTemplateArgs()) { TemplateArgumentListInfo ToTAInfo; if (Error Err = ImportTemplateArgumentListInfo( E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), @@ -7501,8 +7516,9 @@ TemplateArgumentListInfo ToTAInfo; TemplateArgumentListInfo *ResInfo = nullptr; if (E->hasExplicitTemplateArgs()) { - if (Error Err = - ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) + TemplateArgumentListInfo FromTAInfo; + E->copyTemplateArgumentsInto(FromTAInfo); + if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) return std::move(Err); ResInfo = &ToTAInfo; } @@ -8315,8 +8331,14 @@ return std::move(Err); TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( QualType(Spec->getAsType(), 0), ToTLoc); - Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), - ToLocalEndLoc); + if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) + // ToLocalBeginLoc is here the location of the 'template' keyword. + Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), + ToLocalEndLoc); + else + // No location for 'template' keyword here. + Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), + ToLocalEndLoc); break; } diff --git a/clang/test/Import/cxx-anon-namespace/test.cpp b/clang/test/Import/cxx-anon-namespace/test.cpp --- a/clang/test/Import/cxx-anon-namespace/test.cpp +++ b/clang/test/Import/cxx-anon-namespace/test.cpp @@ -8,7 +8,7 @@ // CHECK: F.cpp:1:1 // The nested anonymous namespace. // CHECK-NEXT: NamespaceDecl -// CHECK-SAME: +// CHECK-SAME: line:21:11 // CHECK: FunctionDecl // CHECK-SAME: func4 // CHECK-NEXT: CompoundStmt diff --git a/clang/test/Import/enum/test.cpp b/clang/test/Import/enum/test.cpp --- a/clang/test/Import/enum/test.cpp +++ b/clang/test/Import/enum/test.cpp @@ -1,5 +1,7 @@ // RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | FileCheck %s +// CHECK: |-EnumDecl +// CHECK-SAME: Inputs/S.cpp:1:1, line:4:1> line:1:6 E // CHECK: OpaqueWithType 'long' void expr() { diff --git a/clang/test/Import/namespace/Inputs/NS.cpp b/clang/test/Import/namespace/Inputs/NS.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Import/namespace/Inputs/NS.cpp @@ -0,0 +1,5 @@ +namespace NS { +void f1(); +void f2(); +const int A = 3; +}; // namespace NS diff --git a/clang/test/Import/namespace/test.cpp b/clang/test/Import/namespace/test.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Import/namespace/test.cpp @@ -0,0 +1,8 @@ +// RUN: clang-import-test -dump-ast -import %S/Inputs/NS.cpp -expression %s | FileCheck %s + +// CHECK: `-NamespaceDecl +// CHECK-SAME: Inputs/NS.cpp:1:1, line:5:1> line:1:11 NS + +void expr() { + static_assert(NS::A == 3); +} diff --git a/clang/test/Import/struct-and-var/test.cpp b/clang/test/Import/struct-and-var/test.cpp --- a/clang/test/Import/struct-and-var/test.cpp +++ b/clang/test/Import/struct-and-var/test.cpp @@ -1,4 +1,8 @@ -// RUN: clang-import-test --import %S/Inputs/S1.cpp --import %S/Inputs/S2.cpp -expression %s +// RUN: clang-import-test -dump-ast --import %S/Inputs/S1.cpp --import %S/Inputs/S2.cpp -expression %s | FileCheck %s + +// CHECK: `-CXXRecordDecl +// CHECK-SAME: Inputs/S2.cpp:1:1, line:3:1> line:1:8 struct F + void expr() { struct F f; int x = f.a; diff --git a/clang/test/Import/template-specialization/test.cpp b/clang/test/Import/template-specialization/test.cpp --- a/clang/test/Import/template-specialization/test.cpp +++ b/clang/test/Import/template-specialization/test.cpp @@ -1,4 +1,7 @@ -// RUN: clang-import-test -import %S/Inputs/T.cpp -expression %s +// RUN: clang-import-test -dump-ast -import %S/Inputs/T.cpp -expression %s | FileCheck %s + +// CHECK: |-ClassTemplateSpecializationDecl +// CHECK-SAME: line:4:20 struct A void expr() { A::B b1;