]> granicus.if.org Git - clang/commitdiff
Copy over attributes to instantiated variable.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 12 Jul 2010 21:12:19 +0000 (21:12 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 12 Jul 2010 21:12:19 +0000 (21:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108195 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
lib/AST/DeclBase.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
lib/Sema/TreeTransform.h

index 2d2407ffb18d67eeb49b29a056160d5c59ab5578..cc0124394b9dc1ca75cb61722f10ac2da062c06b 100644 (file)
@@ -312,6 +312,7 @@ public:
     return getAttrsImpl();    // Uncommon case, out of line hash lookup.
   }
   void swapAttrs(Decl *D);
+  void copyAttrs(Decl *D);
   void invalidateAttrs();
 
   template<typename T> const T *getAttr() const {
index 9027a131434b9a53e9ee9df91bd413e4b749d19a..ddedc65a1bdb24a9c3e88a252b9dccc3752e7b03 100644 (file)
@@ -372,6 +372,17 @@ void Decl::swapAttrs(Decl *RHS) {
   RHS->HasAttrs = true;
 }
 
+void Decl::copyAttrs(Decl *SRC) {
+  if (!SRC->hasAttrs())
+    return;
+  ASTContext &Context = getASTContext();
+  for (const Attr *attr = SRC->getAttrs(); attr; attr = attr->getNext()) {
+    Attr *NewAttr = attr->clone(Context);
+    addAttr(const_cast<Attr*>(NewAttr));
+  }
+  HasAttrs = true;
+}
+
 
 void Decl::Destroy(ASTContext &C) {
   // Free attributes for this decl.
index 5778a827fcfe167d9894c843701399598f2bf73b..3a0e43672d14c45610af3a85e2d959f7e2cde328 100644 (file)
@@ -2591,7 +2591,10 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
       ParentDC->isFunctionOrMethod()) {
     // D is a local of some kind. Look into the map of local
     // declarations to their instantiations.
-    return cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D));
+    NamedDecl *ND = 
+      cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D));
+    ND->copyAttrs(D);
+    return ND;
   }
 
   if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
index 2e92d3273689129b5384c84484a6d2001f731c6d..db5e2d10f44140f1d9bd0dcbd225795f41e05ffa 100644 (file)
@@ -6279,11 +6279,6 @@ TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
   if (!ND)
     return SemaRef.ExprError();
   
-  // Is this instantiation of a __block variable?
-  ValueDecl *V = E->getDecl();
-  if (V->getAttr<BlocksAttr>())
-    ND->addAttr(::new (SemaRef.Context) BlocksAttr(BlocksAttr::ByRef));
-  
   if (!getDerived().AlwaysRebuild() &&
       ND == E->getDecl()) {
     // Mark it referenced in the new context regardless.