]> granicus.if.org Git - clang/commitdiff
[modules] Fix assert if multiple update records provide a definition for a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 26 Oct 2016 02:31:56 +0000 (02:31 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 26 Oct 2016 02:31:56 +0000 (02:31 +0000)
class template specialization and that specialization has attributes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285160 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTReaderDecl.cpp
test/Modules/Inputs/templates-left.h
test/Modules/Inputs/templates-right.h
test/Modules/Inputs/templates-top.h
test/Modules/templates.mm

index 94097cd2e1baf5a44f08783ed29627c1876143b8..07df7548e5fa6db2b94509a555474941c96f7d7a 100644 (file)
@@ -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;
     }
index cbe89434f9f390dfaa0e545f112dad02504a7401..4f7abeef1fa061b640dbee158f94c17c97f23be2 100644 (file)
@@ -70,3 +70,5 @@ namespace EmitDefaultedSpecialMembers {
 inline int *getStaticDataMemberLeft() {
   return WithUndefinedStaticDataMember<int[]>::undefined;
 }
+
+inline WithAttributes<int> make_with_attributes_left() { return WithAttributes<int>(); }
index 32487c60c2692df66021dc61b58c02994bb45da2..bb3f7c30182a10f019e505c90c50a356fdeceee9 100644 (file)
@@ -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>(); }
index a08268352399de3abb9cf26fe4763c977cc26d6a..207d705432e8ec25dc4bbc6b07abf2f7d64bb0e9 100644 (file)
@@ -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();
index cd80e2480bfeb2176c8be6d7152ccc8c35b3fd04..79e975a1ad12964af785d9daeaa34c990fe934ae 100644 (file)
@@ -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, "");
+}