From 19f74acdf8842ceece578b7307884f5ba22d7f59 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 6 Jul 2011 15:46:09 +0000 Subject: [PATCH] Use attributes from the definition (if available) when instantiating functions. Fixes PR10272. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134491 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 2 +- lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 +++++++-- test/CodeGenCXX/noinline-template.cpp | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/CodeGenCXX/noinline-template.cpp diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 5feb94f23f..67a2678690 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -4838,7 +4838,7 @@ public: bool Complain = true); void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, - Decl *Pattern, Decl *Inst); + const Decl *Pattern, Decl *Inst); bool InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 0a05d0e304..29385e50b8 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -59,7 +59,7 @@ bool TemplateDeclInstantiator::SubstQualifier(const TagDecl *OldDecl, // FIXME: Is this still too simple? void Sema::InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, - Decl *Tmpl, Decl *New) { + const Decl *Tmpl, Decl *New) { for (AttrVec::const_iterator i = Tmpl->attr_begin(), e = Tmpl->attr_end(); i != e; ++i) { const Attr *TmplAttr = *i; @@ -2283,7 +2283,12 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New, EPI)); } - SemaRef.InstantiateAttrs(TemplateArgs, Tmpl, New); + const FunctionDecl* Definition = Tmpl; + + // Get the definition. Leaves the variable unchanged if undefined. + Tmpl->isDefined(Definition); + + SemaRef.InstantiateAttrs(TemplateArgs, Definition, New); return false; } diff --git a/test/CodeGenCXX/noinline-template.cpp b/test/CodeGenCXX/noinline-template.cpp new file mode 100644 index 0000000000..6ee3935bc0 --- /dev/null +++ b/test/CodeGenCXX/noinline-template.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s + +// This was a problem in Sema, but only shows up as noinline missing +// in CodeGen. + +// CHECK: define linkonce_odr void @_ZN6VectorIiE13growStorageByEv(%struct.Vector* %this) nounwind noinline + +template struct Vector { + void growStorageBy(); +}; +template __attribute__((noinline)) void Vector::growStorageBy() { +} +void foo() { + Vector strs; + strs.growStorageBy(); +} -- 2.40.0