r331762 - [ASTImporter] Properly import SourceLocations of Attrs
Aleksei Sidorin via cfe-commits
cfe-commits at lists.llvm.org
Tue May 8 05:45:22 PDT 2018
Author: a.sidorin
Date: Tue May 8 05:45:21 2018
New Revision: 331762
URL: http://llvm.org/viewvc/llvm-project?rev=331762&view=rev
Log:
[ASTImporter] Properly import SourceLocations of Attrs
Patch by Rafael Stahl!
Differential Revision: https://reviews.llvm.org/D46115
Added:
cfe/trunk/test/Import/attr/
cfe/trunk/test/Import/attr/Inputs/
cfe/trunk/test/Import/attr/Inputs/S.cpp
cfe/trunk/test/Import/attr/test.cpp
Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp
Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=331762&r1=331761&r2=331762&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Tue May 8 05:45:21 2018
@@ -41,6 +41,7 @@ class NamedDecl;
class Stmt;
class TagDecl;
class TypeSourceInfo;
+class Attr;
/// \brief Imports selected nodes from one AST context into another context,
/// merging AST nodes where appropriate.
@@ -126,6 +127,12 @@ class TypeSourceInfo;
/// context, or NULL if an error occurred.
TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
+ /// \brief Import the given attribute from the "from" context into the
+ /// "to" context.
+ ///
+ /// \returns the equivalent attribute in the "to" context.
+ Attr *Import(const Attr *FromAttr);
+
/// \brief Import the given declaration from the "from" context into the
/// "to" context.
///
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=331762&r1=331761&r2=331762&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue May 8 05:45:21 2018
@@ -2687,8 +2687,8 @@ Decl *ASTNodeImporter::VisitIndirectFiel
Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
{NamedChain, D->getChainingSize()});
- for (const auto *Attr : D->attrs())
- ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
+ for (const auto *A : D->attrs())
+ ToIndirectField->addAttr(Importer.Import(A));
ToIndirectField->setAccess(D->getAccess());
ToIndirectField->setLexicalDeclContext(LexicalDC);
@@ -4766,15 +4766,8 @@ Stmt *ASTNodeImporter::VisitAttributedSt
SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
ArrayRef<const Attr*> FromAttrs(S->getAttrs());
SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
- ASTContext &_ToContext = Importer.getToContext();
- std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
- [&_ToContext](const Attr *A) -> const Attr * {
- return A->clone(_ToContext);
- });
- for (const auto *ToA : ToAttrs) {
- if (!ToA)
- return nullptr;
- }
+ if (ImportContainerChecked(FromAttrs, ToAttrs))
+ return nullptr;
Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
if (!ToSubStmt && S->getSubStmt())
return nullptr;
@@ -6657,6 +6650,12 @@ TypeSourceInfo *ASTImporter::Import(Type
Import(FromTSI->getTypeLoc().getLocStart()));
}
+Attr *ASTImporter::Import(const Attr *FromAttr) {
+ Attr *ToAttr = FromAttr->clone(ToContext);
+ ToAttr->setRange(Import(FromAttr->getRange()));
+ return ToAttr;
+}
+
Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD);
if (Pos != ImportedDecls.end()) {
@@ -7290,8 +7289,8 @@ void ASTImporter::CompleteDecl (Decl *D)
Decl *ASTImporter::Imported(Decl *From, Decl *To) {
if (From->hasAttrs()) {
- for (auto *FromAttr : From->getAttrs())
- To->addAttr(FromAttr->clone(To->getASTContext()));
+ for (const auto *FromAttr : From->getAttrs())
+ To->addAttr(Import(FromAttr));
}
if (From->isUsed()) {
To->setIsUsed();
Added: cfe/trunk/test/Import/attr/Inputs/S.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/attr/Inputs/S.cpp?rev=331762&view=auto
==============================================================================
--- cfe/trunk/test/Import/attr/Inputs/S.cpp (added)
+++ cfe/trunk/test/Import/attr/Inputs/S.cpp Tue May 8 05:45:21 2018
@@ -0,0 +1,13 @@
+extern void f() __attribute__((const));
+
+struct S {
+ struct {
+ int a __attribute__((packed));
+ };
+};
+
+void stmt() {
+#pragma unroll
+ for (;;)
+ ;
+}
Added: cfe/trunk/test/Import/attr/test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/attr/test.cpp?rev=331762&view=auto
==============================================================================
--- cfe/trunk/test/Import/attr/test.cpp (added)
+++ cfe/trunk/test/Import/attr/test.cpp Tue May 8 05:45:21 2018
@@ -0,0 +1,26 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | FileCheck %s
+// CHECK: FunctionDecl
+// CHECK-SAME: S.cpp:1:1, col:13
+// CHECK-NEXT: ConstAttr
+// CHECK-SAME: col:32
+
+// CHECK: IndirectFieldDecl
+// CHECK-NEXT: Field
+// CHECK-NEXT: Field
+// CHECK-NEXT: PackedAttr
+// CHECK-SAME: col:26
+
+// CHECK: AttributedStmt
+// CHECK-NEXT: LoopHintAttr
+// CHECK-SAME: line:10:9
+
+extern void f() __attribute__((const));
+
+struct S;
+
+void stmt();
+
+void expr() {
+ f();
+ struct S s;
+}
More information about the cfe-commits
mailing list