[cfe-commits] r77660 - in /cfe/trunk/lib/Sema: ParseAST.cpp Sema.h SemaDecl.cpp SemaDeclAttr.cpp
Ryan Flynn
pizza at parseerror.com
Thu Jul 30 19:52:19 PDT 2009
Author: pizza
Date: Thu Jul 30 21:52:19 2009
New Revision: 77660
URL: http://llvm.org/viewvc/llvm-project?rev=77660&view=rev
Log:
PR3679 - enable #pragma weak aliasing.
Modified:
cfe/trunk/lib/Sema/ParseAST.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/lib/Sema/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParseAST.cpp?rev=77660&r1=77659&r2=77660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Thu Jul 30 21:52:19 2009
@@ -68,6 +68,12 @@
Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
};
+ // process any TopLevelDecls generated by #pragma weak
+ for (llvm::SmallVector<Decl*,2>::iterator
+ I = S.WeakTopLevelDecls().begin(),
+ E = S.WeakTopLevelDecls().end(); I != E; ++I)
+ Consumer->HandleTopLevelDecl(DeclGroupRef(*I));
+
Consumer->HandleTranslationUnit(Ctx);
if (PrintStats) {
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=77660&r1=77659&r2=77660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Jul 30 21:52:19 2009
@@ -254,6 +254,13 @@
};
llvm::DenseMap<IdentifierInfo*,WeakInfo> WeakUndeclaredIdentifiers;
+ /// WeakTopLevelDecl - Translation-unit scoped declarations generated by
+ /// #pragma weak during processing of other Decls.
+ /// I couldn't figure out a clean way to generate these in-line, so
+ /// we store them here and handle separately -- which is a hack.
+ /// It would be best to refactor this.
+ llvm::SmallVector<Decl*,2> WeakTopLevelDecl;
+
IdentifierResolver IdResolver;
/// Translation Unit Scope - useful to Objective-C actions that need
@@ -381,6 +388,9 @@
llvm::SmallVector<SwitchStmt*,8> &getSwitchStack() {
return CurBlock ? CurBlock->SwitchStack : FunctionSwitchStack;
}
+
+ /// WeakTopLevelDeclDecls - access to #pragma weak-generated Decls
+ llvm::SmallVector<Decl*,2> &WeakTopLevelDecls() { return WeakTopLevelDecl; }
virtual void ActOnComment(SourceRange Comment);
@@ -2948,7 +2958,8 @@
SourceLocation LParenLoc,
SourceLocation RParenLoc);
- void DeclApplyPragmaWeak(NamedDecl *D, WeakInfo &W);
+ NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II);
+ void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
/// ActOnPragmaWeakID - Called on well formed #pragma weak ident.
virtual void ActOnPragmaWeakID(IdentifierInfo* WeakName,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=77660&r1=77659&r2=77660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jul 30 21:52:19 2009
@@ -5220,7 +5220,7 @@
if (PrevDecl) {
if (!PrevDecl->hasAttr<AliasAttr>())
if (NamedDecl *ND = dyn_cast<NamedDecl>(PrevDecl))
- DeclApplyPragmaWeak(ND, W);
+ DeclApplyPragmaWeak(TUScope, ND, W);
} else {
(void)WeakUndeclaredIdentifiers.insert(
std::pair<IdentifierInfo*,WeakInfo>(AliasName, W));
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=77660&r1=77659&r2=77660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Jul 30 21:52:19 2009
@@ -1820,8 +1820,9 @@
/// DeclClonePragmaWeak - clone existing decl (maybe definition),
/// #pragma weak needs a non-definition decl and source may not have one
-static NamedDecl * DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II)
+NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II)
{
+ assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
NamedDecl *NewD = 0;
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
NewD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(),
@@ -1837,8 +1838,7 @@
/// DeclApplyPragmaWeak - A declaration (maybe definition) needs #pragma weak
/// applied to it, possibly with an alias.
-void Sema::DeclApplyPragmaWeak(NamedDecl *ND, WeakInfo &W) {
- assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
+void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W) {
if (!W.getUsed()) { // only do this once
W.setUsed(true);
if (W.getAlias()) { // clone decl, impersonate __attribute(weak,alias(...))
@@ -1846,7 +1846,13 @@
NamedDecl *NewD = DeclClonePragmaWeak(ND, W.getAlias());
NewD->addAttr(::new (Context) AliasAttr(NDId->getName()));
NewD->addAttr(::new (Context) WeakAttr());
- ND->getDeclContext()->addDecl(NewD);
+ WeakTopLevelDecl.push_back(NewD);
+ // FIXME: "hideous" code from Sema::LazilyCreateBuiltin
+ // to insert Decl at TU scope, sorry.
+ DeclContext *SavedContext = CurContext;
+ CurContext = Context.getTranslationUnitDecl();
+ PushOnScopeChains(NewD, S);
+ CurContext = SavedContext;
} else { // just add weak to existing
ND->addAttr(::new (Context) WeakAttr());
}
@@ -1862,8 +1868,8 @@
if (ND->hasLinkage()) {
WeakInfo W = WeakUndeclaredIdentifiers.lookup(ND->getIdentifier());
if (W != WeakInfo()) {
- // Declaration referenced by #pragma weak before it was declared
- DeclApplyPragmaWeak(ND, W);
+ // Identifier referenced by #pragma weak before it was declared
+ DeclApplyPragmaWeak(S, ND, W);
WeakUndeclaredIdentifiers[ND->getIdentifier()] = W;
}
}
More information about the cfe-commits
mailing list