summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Serialization/ASTReaderDecl.cpp5
-rw-r--r--clang/test/Modules/Inputs/templates-left.h2
-rw-r--r--clang/test/Modules/Inputs/templates-right.h2
-rw-r--r--clang/test/Modules/Inputs/templates-top.h5
-rw-r--r--clang/test/Modules/templates.mm7
5 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 94097cd2e1b..07df7548e5f 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3930,7 +3930,10 @@ void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile,
if (Record[Idx++]) {
AttrVec Attrs;
Reader.ReadAttributes(F, Attrs, Record, Idx);
- D->setAttrsImpl(Attrs, Reader.getContext());
+ // If the declaration already has attributes, we assume that some other
+ // AST file already loaded them.
+ if (!D->hasAttrs())
+ D->setAttrsImpl(Attrs, Reader.getContext());
}
break;
}
diff --git a/clang/test/Modules/Inputs/templates-left.h b/clang/test/Modules/Inputs/templates-left.h
index cbe89434f9f..4f7abeef1fa 100644
--- a/clang/test/Modules/Inputs/templates-left.h
+++ b/clang/test/Modules/Inputs/templates-left.h
@@ -70,3 +70,5 @@ namespace EmitDefaultedSpecialMembers {
inline int *getStaticDataMemberLeft() {
return WithUndefinedStaticDataMember<int[]>::undefined;
}
+
+inline WithAttributes<int> make_with_attributes_left() { return WithAttributes<int>(); }
diff --git a/clang/test/Modules/Inputs/templates-right.h b/clang/test/Modules/Inputs/templates-right.h
index 32487c60c26..bb3f7c30182 100644
--- a/clang/test/Modules/Inputs/templates-right.h
+++ b/clang/test/Modules/Inputs/templates-right.h
@@ -51,3 +51,5 @@ void outOfLineInlineUseRightH(void (OutOfLineInline<int>::*)() = &OutOfLineInlin
inline int *getStaticDataMemberRight() {
return WithUndefinedStaticDataMember<int[]>::undefined;
}
+
+inline WithAttributes<int> make_with_attributes_right() { return WithAttributes<int>(); }
diff --git a/clang/test/Modules/Inputs/templates-top.h b/clang/test/Modules/Inputs/templates-top.h
index a0826835239..207d705432e 100644
--- a/clang/test/Modules/Inputs/templates-top.h
+++ b/clang/test/Modules/Inputs/templates-top.h
@@ -58,3 +58,8 @@ namespace EmitDefaultedSpecialMembers {
template<typename T> struct WithUndefinedStaticDataMember {
static T undefined;
};
+
+template<typename T> struct __attribute__((packed, aligned(2))) WithAttributes {
+ T value;
+};
+WithAttributes<int> *get_with_attributes();
diff --git a/clang/test/Modules/templates.mm b/clang/test/Modules/templates.mm
index cd80e2480bf..79e975a1ad1 100644
--- a/clang/test/Modules/templates.mm
+++ b/clang/test/Modules/templates.mm
@@ -116,4 +116,9 @@ void testStaticDataMember() {
(void) getStaticDataMemberRight();
}
-
+void testWithAttributes() {
+ auto a = make_with_attributes_left();
+ auto b = make_with_attributes_right();
+ static_assert(alignof(decltype(a)) == 2, "");
+ static_assert(alignof(decltype(b)) == 2, "");
+}
OpenPOWER on IntegriCloud