Copy over attributes to instantiated variable.

llvm-svn: 108195
This commit is contained in:
Fariborz Jahanian 2010-07-12 21:12:19 +00:00
parent 553f3a9b30
commit 8308585a1e
4 changed files with 16 additions and 6 deletions

View 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 {

View 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.

View 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)) {

View 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.