From e7ffbe233ed04f921a008ed893672ee759d1a0ad Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 13 Jul 2010 20:05:58 +0000 Subject: [PATCH] More block instantiation stuff. Set variable/param DeclContext to block context when first instantiating them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108266 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiate.cpp | 4 ++++ lib/Sema/SemaTemplateInstantiateDecl.cpp | 3 +++ lib/Sema/TreeTransform.h | 4 ---- test/CodeGenCXX/instantiate-blocks.cpp | 26 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 6db0916e44..539b4c409f 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1067,6 +1067,10 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); + // Set DeclContext if inside a Block. + if (BlockScopeInfo *CurBlock = getCurBlock()) + NewParm->setDeclContext(CurBlock->TheDecl); + return NewParm; } diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 2fd3528532..b80e824bfd 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -400,6 +400,9 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Var); } InstantiateAttrs(D, Var); + // Set DeclContext if inside a Block. + if (BlockScopeInfo *CurBlock = SemaRef.getCurBlock()) + D->setDeclContext(CurBlock->TheDecl); // Link instantiations of static data members back to the template from // which they were instantiated. diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 132d04927b..17103c515f 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -4198,10 +4198,6 @@ TreeTransform::TransformDeclRefExpr(DeclRefExpr *E) { if (!ND) return SemaRef.ExprError(); - // Set DeclContext if inside a Block. - if (BlockScopeInfo *CurBlock = SemaRef.getCurBlock()) - ND->setDeclContext(CurBlock->TheDecl); - if (!getDerived().AlwaysRebuild() && Qualifier == E->getQualifier() && ND == E->getDecl() && diff --git a/test/CodeGenCXX/instantiate-blocks.cpp b/test/CodeGenCXX/instantiate-blocks.cpp index c8f897de82..e206582191 100644 --- a/test/CodeGenCXX/instantiate-blocks.cpp +++ b/test/CodeGenCXX/instantiate-blocks.cpp @@ -31,3 +31,29 @@ void test2(void) { foo(100, 'a'); } + +namespace rdar6182276 { +extern "C" { +int printf(const char *, ...); +} + +template T foo(T t) +{ + void (^testing)(int) = ^(int bar) { printf("bar is %d\n", bar); }; + printf("bar is\n"); + return 1; +} + +template void gorf(T t) +{ + foo(t); +} + + +void test(void) +{ + gorf(2); +} +} + + -- 2.40.0