[cfe-commits] r86344 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-attr.cpp

Anders Carlsson andersca at mac.com
Fri Nov 6 22:07:59 PST 2009


Author: andersca
Date: Sat Nov  7 00:07:58 2009
New Revision: 86344

URL: http://llvm.org/viewvc/llvm-project?rev=86344&view=rev
Log:
When instantiating a field decl, make sure to clone its attributes. With this change FileCheck no longer crashes when it's run without any arguments.

Added:
    cfe/trunk/test/SemaTemplate/instantiate-attr.cpp
Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=86344&r1=86343&r2=86344&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Sat Nov  7 00:07:58 2009
@@ -28,6 +28,8 @@
     DeclContext *Owner;
     const MultiLevelTemplateArgumentList &TemplateArgs;
 
+    void InstantiateAttrs(Decl *Tmpl, Decl *New);
+      
   public:
     typedef Sema::OwningExprResult OwningExprResult;
 
@@ -89,6 +91,18 @@
   };
 }
 
+// FIXME: Is this too simple?
+void TemplateDeclInstantiator::InstantiateAttrs(Decl *Tmpl, Decl *New) {
+  for (const Attr *TmplAttr = Tmpl->getAttrs(); TmplAttr; 
+       TmplAttr = TmplAttr->getNext()) {
+    
+    // FIXME: Is cloning correct for all attributes?
+    Attr *NewAttr = TmplAttr->clone(SemaRef.Context);
+    
+    New->addAttr(NewAttr);
+  }
+}
+
 Decl *
 TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
   assert(false && "Translation units cannot be instantiated");
@@ -258,6 +272,8 @@
     return 0;
   }
 
+  InstantiateAttrs(D, Field);
+  
   if (Invalid)
     Field->setInvalidDecl();
 

Added: cfe/trunk/test/SemaTemplate/instantiate-attr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-attr.cpp?rev=86344&view=auto

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-attr.cpp (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-attr.cpp Sat Nov  7 00:07:58 2009
@@ -0,0 +1,7 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+template <typename T>
+struct A {
+  char a __attribute__((aligned(16)));
+};
+int a[sizeof(A<int>) == 16 ? 1 : -1];
+





More information about the cfe-commits mailing list