Propagate the spelling list index for an attribute across template instantiation.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 29 Jan 2013 04:21:28 +0000 (04:21 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 29 Jan 2013 04:21:28 +0000 (04:21 +0000)
llvm-svn: 173768

clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/cxx11-attr-print.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

index bbe09f7..58e663d 100644 (file)
@@ -6527,9 +6527,9 @@ public:
 
   /// AddAlignedAttr - Adds an aligned attribute to a particular declaration.
   void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
-                      bool isDeclSpec, unsigned SpellingListIndex = 0);
+                      bool isDeclSpec, unsigned SpellingListIndex);
   void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T,
-                      bool isDeclSpec);
+                      bool isDeclSpec, unsigned SpellingListIndex);
 
   /// \brief The kind of conversion being performed.
   enum CheckedConversionKind {
index a4b8c35..0e51ba3 100644 (file)
@@ -3330,11 +3330,11 @@ void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E,
 }
 
 void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *TS, 
-                          bool isDeclSpec) {
+                          bool isDeclSpec, unsigned SpellingListIndex) {
   // FIXME: Cache the number on the Attr object if non-dependent?
   // FIXME: Perform checking of type validity
   D->addAttr(::new (Context) AlignedAttr(AttrRange, Context, false, TS, 
-                                         isDeclSpec));
+                                         isDeclSpec, SpellingListIndex));
   return;
 }
 
index b679d49..f5405ff 100644 (file)
@@ -80,15 +80,17 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
                                         TemplateArgs);
           if (!Result.isInvalid())
             AddAlignedAttr(Aligned->getLocation(), New, Result.takeAs<Expr>(), 
-                           Aligned->getIsMSDeclSpec());
+                           Aligned->getIsMSDeclSpec(),
+                           Aligned->getSpellingListIndex());
         } else {
           TypeSourceInfo *Result = SubstType(Aligned->getAlignmentType(),
                                              TemplateArgs,
                                              Aligned->getLocation(),
                                              DeclarationName());
           if (Result)
-            AddAlignedAttr(Aligned->getLocation(), New, Result, 
-                           Aligned->getIsMSDeclSpec());
+            AddAlignedAttr(Aligned->getLocation(), New, Result,
+                           Aligned->getIsMSDeclSpec(),
+                           Aligned->getSpellingListIndex());
         }
         continue;
       }
index 77df65a..b4f5859 100644 (file)
@@ -55,3 +55,24 @@ inline void f7 [[gnu::gnu_inline]] ();
 // arguments printing
 // CHECK: __attribute__((format("printf", 2, 3)));
 void f8 (void *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
+
+// CHECK: int m __attribute__((aligned(4
+// CHECK: int n alignas(4
+// CHECK: static int f() __attribute__((pure))
+// CHECK: static int g() {{\[}}[gnu::pure]]
+template <typename T> struct S {
+  __attribute__((aligned(4))) int m;
+  alignas(4) int n;
+  __attribute__((pure)) static int f() {
+    return 0;
+  }
+  [[gnu::pure]] static int g() {
+    return 1;
+  }
+};
+
+// CHECK: int m __attribute__((aligned(4
+// CHECK: int n alignas(4
+// CHECK: static int f() __attribute__((pure))
+// CHECK: static int g() {{\[}}[gnu::pure]]
+template struct S<int>;
index d936e26..3530e7e 100644 (file)
@@ -937,7 +937,7 @@ void EmitClangAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
       OS << ", ";
       (*ai)->writeCloneArgs(OS);
     }
-    OS << ");\n}\n\n";
+    OS << ", getSpellingListIndex());\n}\n\n";
 
     writePrettyPrintFunction(R, Args, OS);
   }