[cfe-commits] r134491 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaTemplateInstantiateDecl.cpp test/CodeGenCXX/noinline-template.cpp
Rafael Espindola
rafael.espindola at gmail.com
Wed Jul 6 08:46:09 PDT 2011
Author: rafael
Date: Wed Jul 6 10:46:09 2011
New Revision: 134491
URL: http://llvm.org/viewvc/llvm-project?rev=134491&view=rev
Log:
Use attributes from the definition (if available) when
instantiating functions.
Fixes PR10272.
Added:
cfe/trunk/test/CodeGenCXX/noinline-template.cpp
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=134491&r1=134490&r2=134491&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jul 6 10:46:09 2011
@@ -4838,7 +4838,7 @@
bool Complain = true);
void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs,
- Decl *Pattern, Decl *Inst);
+ const Decl *Pattern, Decl *Inst);
bool
InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=134491&r1=134490&r2=134491&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Jul 6 10:46:09 2011
@@ -59,7 +59,7 @@
// 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 @@
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;
}
Added: cfe/trunk/test/CodeGenCXX/noinline-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/noinline-template.cpp?rev=134491&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/noinline-template.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/noinline-template.cpp Wed Jul 6 10:46:09 2011
@@ -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 <class Ty> struct Vector {
+ void growStorageBy();
+};
+template <class T> __attribute__((noinline)) void Vector<T>::growStorageBy() {
+}
+void foo() {
+ Vector<int> strs;
+ strs.growStorageBy();
+}
More information about the cfe-commits
mailing list