From a5aaca9295144f29814c7367424d551ff49ecb3e Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 29 Jan 2013 04:21:28 +0000 Subject: [PATCH] Propagate the spelling list index for an attribute across template instantiation. llvm-svn: 173768 --- clang/include/clang/Sema/Sema.h | 4 ++-- clang/lib/Sema/SemaDeclAttr.cpp | 4 ++-- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 8 +++++--- clang/test/SemaCXX/cxx11-attr-print.cpp | 21 +++++++++++++++++++++ clang/utils/TableGen/ClangAttrEmitter.cpp | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index bbe09f7..58e663d 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/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/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index a4b8c35..0e51ba3 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index b679d49..f5405ff 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/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/clang/test/SemaCXX/cxx11-attr-print.cpp b/clang/test/SemaCXX/cxx11-attr-print.cpp index 77df65a..b4f5859 100644 --- a/clang/test/SemaCXX/cxx11-attr-print.cpp +++ b/clang/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/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index d936e26..3530e7e 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/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); } -- 2.7.4