r356151 - [ASTImporter] Fix import of NestedNameSpecifierLoc.
Balazs Keri via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 14 07:20:23 PDT 2019
Author: balazske
Date: Thu Mar 14 07:20:23 2019
New Revision: 356151
URL: http://llvm.org/viewvc/llvm-project?rev=356151&view=rev
Log:
[ASTImporter] Fix import of NestedNameSpecifierLoc.
Summary:
Import type location in case of TypeSpec and TypeSpecWithTemplate.
Without this fix the imported NespedNameSpecifierLoc will have an
invalid begin location.
Reviewers: a.sidorin, shafik, a_sidorin, martong
Reviewed By: a_sidorin
Subscribers: rnkovacs, jdoerfert, dkrupp, martong, Szelethus, gamesh411, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D55358
Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=356151&r1=356150&r2=356151&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Thu Mar 14 07:20:23 2019
@@ -8092,8 +8092,11 @@ ASTImporter::Import_New(NestedNameSpecif
case NestedNameSpecifier::TypeSpec:
case NestedNameSpecifier::TypeSpecWithTemplate: {
+ SourceLocation ToTLoc;
+ if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
+ return std::move(Err);
TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo(
- QualType(Spec->getAsType(), 0));
+ QualType(Spec->getAsType(), 0), ToTLoc);
Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
ToLocalEndLoc);
break;
Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=356151&r1=356150&r2=356151&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Thu Mar 14 07:20:23 2019
@@ -1232,6 +1232,26 @@ TEST_P(ImportExpr, DependentSizedArrayTy
has(fieldDecl(hasType(dependentSizedArrayType())))))));
}
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBeginLocOfDeclRefExpr) {
+ Decl *FromTU = getTuDecl(
+ "class A { public: static int X; }; void f() { (void)A::X; }", Lang_CXX);
+ auto From = FirstDeclMatcher<FunctionDecl>().match(
+ FromTU, functionDecl(hasName("f")));
+ ASSERT_TRUE(From);
+ ASSERT_TRUE(
+ cast<CStyleCastExpr>(cast<CompoundStmt>(From->getBody())->body_front())
+ ->getSubExpr()
+ ->getBeginLoc()
+ .isValid());
+ FunctionDecl *To = Import(From, Lang_CXX);
+ ASSERT_TRUE(To);
+ ASSERT_TRUE(
+ cast<CStyleCastExpr>(cast<CompoundStmt>(To->getBody())->body_front())
+ ->getSubExpr()
+ ->getBeginLoc()
+ .isValid());
+}
+
TEST_P(ASTImporterOptionSpecificTestBase,
ImportOfTemplatedDeclOfClassTemplateDecl) {
Decl *FromTU = getTuDecl("template<class X> struct S{};", Lang_CXX);
More information about the cfe-commits
mailing list