summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorRyan Flynn <pizza@parseerror.com>2009-07-31 02:52:19 +0000
committerRyan Flynn <pizza@parseerror.com>2009-07-31 02:52:19 +0000
commitd963a497562efd73b213b79b16aeeb1766b5c83a (patch)
tree88a987ad4dcbd5c192f585333821fd0a20238588 /clang/lib/Sema/SemaDeclAttr.cpp
parent8f416a5138633b9f96f47a66e70afa4acdddc696 (diff)
downloadbcm5719-llvm-d963a497562efd73b213b79b16aeeb1766b5c83a.tar.gz
bcm5719-llvm-d963a497562efd73b213b79b16aeeb1766b5c83a.zip
PR3679 - enable #pragma weak aliasing.
llvm-svn: 77660
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index a8efc2497ad..08b4910a4fd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1820,8 +1820,9 @@ void Sema::ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *Attr
/// 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 @@ static NamedDecl * DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II)
/// 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 @@ void Sema::DeclApplyPragmaWeak(NamedDecl *ND, WeakInfo &W) {
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 @@ void Sema::ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD) {
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;
}
}
OpenPOWER on IntegriCloud