From 31bb0f748b805f1e7ff73694fc63ace3e7876e19 Mon Sep 17 00:00:00 2001 From: Paul Bissonnette Date: Thu, 6 Nov 2014 17:27:03 -0800 Subject: [PATCH] Check return types when returning inside try-finally Summary: Adds a VerifyRetType{C,V} for finally trampoline. Fixes #3998 Reviewed By: @JoelMarcey Differential Revision: D1660033 Signature: t1:1660033:1415294884:3426c5634ca6a09f8fcf74a2b50943ae8e1ac52b --- hphp/compiler/analysis/emitter.cpp | 11 +++++++++++ hphp/test/slow/return_statement/finally-typecheck.php | 14 ++++++++++++++ .../slow/return_statement/finally-typecheck.php.expectf | 3 +++ 3 files changed, 28 insertions(+) create mode 100644 hphp/test/slow/return_statement/finally-typecheck.php create mode 100644 hphp/test/slow/return_statement/finally-typecheck.php.expectf diff --git a/hphp/compiler/analysis/emitter.cpp b/hphp/compiler/analysis/emitter.cpp index 303f4d9fea5..7aaa7817361 100644 --- a/hphp/compiler/analysis/emitter.cpp +++ b/hphp/compiler/analysis/emitter.cpp @@ -1611,6 +1611,11 @@ void EmitterVisitor::emitReturnTrampoline(Emitter& e, auto& t = region->m_returnTargets[sym].target; cases[t->m_state]->set(e); + bool hasConstraint = m_curFunc->retTypeConstraint.hasConstraint(); + if (m_curFunc->isGenerator) { + // Suppress return type checking for generators + hasConstraint = false; + } IterVec iters; // We are emitting a case in a finally epilogue, therefore skip // the current try region and start from its parent @@ -1628,10 +1633,16 @@ void EmitterVisitor::emitReturnTrampoline(Emitter& e, emitVirtualLocal(retLocal); if (sym == StackSym::C) { e.CGetL(retLocal); + if (hasConstraint) { + e.VerifyRetTypeC(); + } e.RetC(); } else { assert(sym == StackSym::V); e.VGetL(retLocal); + if (hasConstraint) { + e.VerifyRetTypeV(); + } e.RetV(); } return; diff --git a/hphp/test/slow/return_statement/finally-typecheck.php b/hphp/test/slow/return_statement/finally-typecheck.php new file mode 100644 index 00000000000..04ce28eef1a --- /dev/null +++ b/hphp/test/slow/return_statement/finally-typecheck.php @@ -0,0 +1,14 @@ +