From 70751f99a8a9d50035f285a22e3aedaeb4a0663b Mon Sep 17 00:00:00 2001 From: mwilliams Date: Wed, 5 Jun 2013 18:55:10 -0700 Subject: [PATCH] Fix a bug for continuations-from-closures that need a local $this If a continuation in a closure needed a $this variable, hhir would fail to initialize it, resulting in reads reporting null. This didn't come up much, because usually we dont need a variable; we can typically use This or BareThis. Its only cases where $this might be passed by reference, or there are dynamic variables that actually require a local $this. --- hphp/runtime/vm/jit/hhbctranslator.cpp | 2 +- .../slow/yield/closure_gen_with_this_loc.php | 21 +++++++++++++++++++ .../closure_gen_with_this_loc.php.expect | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 hphp/test/slow/yield/closure_gen_with_this_loc.php create mode 100644 hphp/test/slow/yield/closure_gen_with_this_loc.php.expect diff --git a/hphp/runtime/vm/jit/hhbctranslator.cpp b/hphp/runtime/vm/jit/hhbctranslator.cpp index 7d7131073..75f56e296 100644 --- a/hphp/runtime/vm/jit/hhbctranslator.cpp +++ b/hphp/runtime/vm/jit/hhbctranslator.cpp @@ -1026,7 +1026,7 @@ void HhbcTranslator::emitCreateCont(bool getArgs, mapContParams(params, origFunc, genFunc)) { static auto const thisStr = StringData::GetStaticString("this"); Id thisId = kInvalidId; - const bool fillThis = origFunc->isNonClosureMethod() && + const bool fillThis = origFunc->isMethod() && !origFunc->isStatic() && ((thisId = genFunc->lookupVarId(thisStr)) != kInvalidId) && (origFunc->lookupVarId(thisStr) == kInvalidId); diff --git a/hphp/test/slow/yield/closure_gen_with_this_loc.php b/hphp/test/slow/yield/closure_gen_with_this_loc.php new file mode 100644 index 000000000..f657062ee --- /dev/null +++ b/hphp/test/slow/yield/closure_gen_with_this_loc.php @@ -0,0 +1,21 @@ +gen(function($x) { var_dump(get_class($x)); }); + foreach ($f() as $e) { + var_dump($e); + } +} + +test(); + +function fiz($x) { return false; } diff --git a/hphp/test/slow/yield/closure_gen_with_this_loc.php.expect b/hphp/test/slow/yield/closure_gen_with_this_loc.php.expect new file mode 100644 index 000000000..d05e649ff --- /dev/null +++ b/hphp/test/slow/yield/closure_gen_with_this_loc.php.expect @@ -0,0 +1,2 @@ +string(1) "X" +NULL