summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAleksei Sidorin <a.sidorin@samsung.com>2018-05-08 12:45:21 +0000
committerAleksei Sidorin <a.sidorin@samsung.com>2018-05-08 12:45:21 +0000
commit8f266dbbdcddb0fb9df96cb02b40550cdfdd5dd6 (patch)
tree0ba17c3384b1a2711d7ded5fb35243bd6887a3e6 /clang
parent7562e34acc73d52a5ef2198fa013e4318dc344ce (diff)
downloadbcm5719-llvm-8f266dbbdcddb0fb9df96cb02b40550cdfdd5dd6.tar.gz
bcm5719-llvm-8f266dbbdcddb0fb9df96cb02b40550cdfdd5dd6.zip
[ASTImporter] Properly import SourceLocations of Attrs
Patch by Rafael Stahl! Differential Revision: https://reviews.llvm.org/D46115 llvm-svn: 331762
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/ASTImporter.h7
-rw-r--r--clang/lib/AST/ASTImporter.cpp25
-rw-r--r--clang/test/Import/attr/Inputs/S.cpp13
-rw-r--r--clang/test/Import/attr/test.cpp26
4 files changed, 58 insertions, 13 deletions
diff --git a/clang/include/clang/AST/ASTImporter.h b/clang/include/clang/AST/ASTImporter.h
index 55e46eb2010..280c4b2a3ff 100644
--- a/clang/include/clang/AST/ASTImporter.h
+++ b/clang/include/clang/AST/ASTImporter.h
@@ -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.
///
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 66b596041fb..ffe1762d674 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -2687,8 +2687,8 @@ Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
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::VisitAttributedStmt(AttributedStmt *S) {
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(TypeSourceInfo *FromTSI) {
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();
diff --git a/clang/test/Import/attr/Inputs/S.cpp b/clang/test/Import/attr/Inputs/S.cpp
new file mode 100644
index 00000000000..28d70c544a7
--- /dev/null
+++ b/clang/test/Import/attr/Inputs/S.cpp
@@ -0,0 +1,13 @@
+extern void f() __attribute__((const));
+
+struct S {
+ struct {
+ int a __attribute__((packed));
+ };
+};
+
+void stmt() {
+#pragma unroll
+ for (;;)
+ ;
+}
diff --git a/clang/test/Import/attr/test.cpp b/clang/test/Import/attr/test.cpp
new file mode 100644
index 00000000000..01ea6c1b0ed
--- /dev/null
+++ b/clang/test/Import/attr/test.cpp
@@ -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;
+}
OpenPOWER on IntegriCloud