From: Richard Smith Date: Tue, 29 Jan 2013 04:21:28 +0000 (+0000) Subject: Propagate the spelling list index for an attribute across template instantiation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f3aacc8c4849c9e0e7a236954725fffdeb917a6;p=clang Propagate the spelling list index for an attribute across template instantiation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173768 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index bbe09f777b..58e663d917 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -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 { diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index a4b8c356dd..0e51ba3ba3 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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; } diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index b679d49215..f5405ff383 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -80,15 +80,17 @@ void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, TemplateArgs); if (!Result.isInvalid()) AddAlignedAttr(Aligned->getLocation(), New, Result.takeAs(), - 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; } diff --git a/test/SemaCXX/cxx11-attr-print.cpp b/test/SemaCXX/cxx11-attr-print.cpp index 77df65a45c..b4f5859409 100644 --- a/test/SemaCXX/cxx11-attr-print.cpp +++ b/test/SemaCXX/cxx11-attr-print.cpp @@ -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 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; diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index d936e260b8..3530e7e738 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -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); }