[cfe-commits] r104106 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/attributes.cpp

Douglas Gregor dgregor at apple.com
Tue May 18 20:39:53 PDT 2010


Author: dgregor
Date: Tue May 18 22:39:53 2010
New Revision: 104106

URL: http://llvm.org/viewvc/llvm-project?rev=104106&view=rev
Log:
Teach clang to instantiate attributes on more declarations. Fixes PR7102.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/attributes.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=104106&r1=104105&r2=104106&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue May 18 22:39:53 2010
@@ -1036,7 +1036,9 @@
                                         OldParm->getStorageClassAsWritten());
   if (!NewParm)
     return 0;
-                                                
+                  
+  // FIXME: Instantiate attributes
+  
   // Mark the (new) default argument as uninstantiated (if any).
   if (OldParm->hasUninstantiatedDefaultArg()) {
     Expr *Arg = OldParm->getUninstantiatedDefaultArg();

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=104106&r1=104105&r2=104106&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue May 18 22:39:53 2010
@@ -31,7 +31,7 @@
     DeclContext *Owner;
     const MultiLevelTemplateArgumentList &TemplateArgs;
 
-    void InstantiateAttrs(Decl *Tmpl, Decl *New);
+    bool InstantiateAttrs(Decl *Tmpl, Decl *New);
       
   public:
     typedef Sema::OwningExprResult OwningExprResult;
@@ -143,7 +143,7 @@
 }
 
 // FIXME: Is this too simple?
-void TemplateDeclInstantiator::InstantiateAttrs(Decl *Tmpl, Decl *New) {
+bool TemplateDeclInstantiator::InstantiateAttrs(Decl *Tmpl, Decl *New) {
   for (const Attr *TmplAttr = Tmpl->getAttrs(); TmplAttr; 
        TmplAttr = TmplAttr->getNext()) {
     
@@ -152,6 +152,8 @@
     
     New->addAttr(NewAttr);
   }
+  
+  return false;
 }
 
 Decl *
@@ -177,7 +179,9 @@
                                  D->getQualifier(),
                                  D->getTargetNameLoc(),
                                  D->getNamespace());
+  InstantiateAttrs(D, Inst);  
   Owner->addDecl(Inst);
+
   return Inst;
 }
 
@@ -353,7 +357,8 @@
 
   Var->setAccess(D->getAccess());
   Var->setUsed(D->isUsed());
-  
+  InstantiateAttrs(D, Var);  
+
   // FIXME: In theory, we could have a previous declaration for variables that
   // are not static data members.
   bool Redeclaration = false;
@@ -531,6 +536,8 @@
   FriendDecl *FD =
     FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(), 
                        cast<NamedDecl>(NewND), D->getFriendLoc());
+  InstantiateAttrs(D, FD);  
+
   FD->setAccess(AS_public);
   Owner->addDecl(FD);
   return FD;
@@ -564,6 +571,7 @@
   Enum->setInstantiationOfMemberEnum(D);
   Enum->setAccess(D->getAccess());
   if (SubstQualifier(D, Enum)) return 0;
+  InstantiateAttrs(D, Enum);
   Owner->addDecl(Enum);
   Enum->startDefinition();
 
@@ -763,6 +771,8 @@
                                 PrevClassTemplate);
   RecordInst->setDescribedClassTemplate(Inst);
 
+  InstantiateAttrs(D, Inst);
+
   if (isFriend) {
     if (PrevClassTemplate)
       Inst->setAccess(PrevClassTemplate->getAccess());
@@ -871,6 +881,8 @@
       !(isFriend && !D->getTemplatedDecl()->isThisDeclarationADefinition()))
     InstTemplate->setInstantiatedFromMemberTemplate(D);
   
+  InstantiateAttrs(D, InstTemplate);
+
   // Make declarations visible in the appropriate context.
   if (!isFriend)
     Owner->addDecl(InstTemplate);
@@ -895,6 +907,8 @@
                             D->getLocation(), D->getIdentifier(),
                             D->getTagKeywordLoc(), PrevDecl);
 
+  InstantiateAttrs(D, Record);
+
   // Substitute the nested name specifier, if any.
   if (SubstQualifier(D, Record))
     return 0;
@@ -1422,6 +1436,7 @@
                                  TTPT->getName(),
                                  D->wasDeclaredWithTypename(),
                                  D->isParameterPack());
+  InstantiateAttrs(D, Inst);
 
   if (D->hasDefaultArgument())
     Inst->setDefaultArgument(D->getDefaultArgumentInfo(), false);  
@@ -1465,6 +1480,7 @@
   if (Invalid)
     Param->setInvalidDecl();
   
+  InstantiateAttrs(D, Param);
   Param->setDefaultArgument(D->getDefaultArgument());
   
   // Introduce this template parameter's instantiation into the instantiation 
@@ -1494,7 +1510,8 @@
                                        D->getDepth() - 1, D->getPosition(),
                                        D->getIdentifier(), InstParams);
   Param->setDefaultArgument(D->getDefaultArgument());
-  
+  InstantiateAttrs(D, Param);
+
   // Introduce this template parameter's instantiation into the instantiation 
   // scope.
   SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param);
@@ -1512,6 +1529,8 @@
                                  D->getIdentLocation(), 
                                  D->getNominatedNamespace(), 
                                  D->getCommonAncestor());
+  InstantiateAttrs(D, Inst);
+
   Owner->addDecl(Inst);
   return Inst;
 }
@@ -1535,6 +1554,7 @@
                                        D->getTargetNestedNameDecl(),
                                        D->getDeclName(),
                                        D->isTypeName());
+  InstantiateAttrs(D, NewUD);
 
   CXXScopeSpec SS;
   SS.setScopeRep(D->getTargetNestedNameDecl());
@@ -1615,8 +1635,10 @@
                                   D->getDeclName(), 0,
                                   /*instantiation*/ true,
                                   /*typename*/ true, D->getTypenameLoc());
-  if (UD)
+  if (UD) {
+    InstantiateAttrs(D, UD);
     SemaRef.Context.setInstantiatedFromUsingDecl(cast<UsingDecl>(UD), D);
+  }
 
   return UD;
 }
@@ -1640,8 +1662,10 @@
                                   D->getDeclName(), 0,
                                   /*instantiation*/ true,
                                   /*typename*/ false, SourceLocation());
-  if (UD)
+  if (UD) {
+    InstantiateAttrs(D, UD);
     SemaRef.Context.setInstantiatedFromUsingDecl(cast<UsingDecl>(UD), D);
+  }
 
   return UD;
 }
@@ -1820,8 +1844,9 @@
     return 0;
 
   InstPartialSpec->setInstantiatedFromMember(PartialSpec);
-  InstPartialSpec->setTypeAsWritten(WrittenTy);
-  
+  InstPartialSpec->setTypeAsWritten(WrittenTy);  
+  InstantiateAttrs(PartialSpec, InstPartialSpec);
+
   // Add this partial specialization to the set of class template partial
   // specializations.
   ClassTemplate->getPartialSpecializations().InsertNode(InstPartialSpec,
@@ -1886,6 +1911,9 @@
   if (Tmpl->isDeleted())
     New->setDeleted();
 
+  if (InstantiateAttrs(Tmpl, New))
+    return true;
+
   // If we are performing substituting explicitly-specified template arguments
   // or deduced template arguments into a function template and we reach this
   // point, we are now past the point where SFINAE applies and have committed

Modified: cfe/trunk/test/SemaTemplate/attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/attributes.cpp?rev=104106&r1=104105&r2=104106&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/attributes.cpp (original)
+++ cfe/trunk/test/SemaTemplate/attributes.cpp Tue May 18 22:39:53 2010
@@ -6,3 +6,24 @@
 
   int __attribute__((__address_space__(N))) *ptr; // expected-error{{attribute requires 1 argument(s)}}
 };
+
+namespace PR7102 {
+
+  class NotTpl {
+  public:
+    union {
+      char space[11];
+      void* ptr;
+    }  __attribute__((packed));
+  };
+  template<unsigned N>
+  class Tpl {
+  public:
+    union {
+      char space[N];
+      void* ptr;
+    }  __attribute__((packed));
+  };
+
+  int array[sizeof(NotTpl) == sizeof(Tpl<11>)? 1 : -1];
+}





More information about the cfe-commits mailing list