From: Argyrios Kyrtzidis Date: Sun, 9 Mar 2014 05:15:28 +0000 (+0000) Subject: [Sema] Fix assertion hit with #pragma weak. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3fcc6f352623a7e13d3f8445b1c977d90812fe73;p=clang [Sema] Fix assertion hit with #pragma weak. rdar://16264844 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203372 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 1d5d9d12c1..7817ca9efc 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4655,6 +4655,8 @@ void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W) { // to insert Decl at TU scope, sorry. DeclContext *SavedContext = CurContext; CurContext = Context.getTranslationUnitDecl(); + NewD->setDeclContext(CurContext); + NewD->setLexicalDeclContext(CurContext); PushOnScopeChains(NewD, S); CurContext = SavedContext; } else { // just add weak to existing diff --git a/test/SemaCXX/pragma-weak.cpp b/test/SemaCXX/pragma-weak.cpp index 057cf6b463..c1ff2062fc 100644 --- a/test/SemaCXX/pragma-weak.cpp +++ b/test/SemaCXX/pragma-weak.cpp @@ -6,3 +6,6 @@ extern "C" { void foo() { }; } + +extern "C" int Test; +#pragma weak test = Test