From bec724926cf653569fe4a9f27fe18a80b2293e00 Mon Sep 17 00:00:00 2001 From: mwilliams Date: Thu, 23 May 2013 07:47:46 -0700 Subject: [PATCH] Fix crash in hphp The AnalysisResult for systemlib.php was allowed to go out of scope, taking the FileScope with it, causing us to crash when trying to flatten systemlib traits. --- hphp/compiler/builtin_symbols.cpp | 3 ++- hphp/compiler/builtin_symbols.h | 1 + hphp/test/slow/traits/sys_trait.php | 9 +++++++++ hphp/test/slow/traits/sys_trait.php.expect | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 hphp/test/slow/traits/sys_trait.php create mode 100644 hphp/test/slow/traits/sys_trait.php.expect diff --git a/hphp/compiler/builtin_symbols.cpp b/hphp/compiler/builtin_symbols.cpp index cee047bd6..7d3bfcfc7 100644 --- a/hphp/compiler/builtin_symbols.cpp +++ b/hphp/compiler/builtin_symbols.cpp @@ -91,6 +91,7 @@ StringToClassScopePtrMap BuiltinSymbols::s_classes; VariableTablePtr BuiltinSymbols::s_variables; ConstantTablePtr BuiltinSymbols::s_constants; StringToTypePtrMap BuiltinSymbols::s_superGlobals; +AnalysisResultPtr BuiltinSymbols::s_systemAr; void *BuiltinSymbols::s_handle_main = nullptr; /////////////////////////////////////////////////////////////////////////////// @@ -329,7 +330,7 @@ bool BuiltinSymbols::Load(AnalysisResultPtr ar, bool extOnly /* = false */) { // parse all PHP files under system/classes if (!extOnly) { - ar = AnalysisResultPtr(new AnalysisResult()); + s_systemAr = ar = AnalysisResultPtr(new AnalysisResult()); ar->loadBuiltinFunctions(); string slib = get_systemlib(); diff --git a/hphp/compiler/builtin_symbols.h b/hphp/compiler/builtin_symbols.h index 41f7dc5d9..42d3be6a4 100644 --- a/hphp/compiler/builtin_symbols.h +++ b/hphp/compiler/builtin_symbols.h @@ -65,6 +65,7 @@ public: static StringToClassScopePtrMap s_classes; static VariableTablePtr s_variables; static ConstantTablePtr s_constants; + static AnalysisResultPtr s_systemAr; static const char *const GlobalNames[]; static int NumGlobalNames(); diff --git a/hphp/test/slow/traits/sys_trait.php b/hphp/test/slow/traits/sys_trait.php new file mode 100644 index 000000000..5f63a4824 --- /dev/null +++ b/hphp/test/slow/traits/sys_trait.php @@ -0,0 +1,9 @@ +view()); +} +test(); + + diff --git a/hphp/test/slow/traits/sys_trait.php.expect b/hphp/test/slow/traits/sys_trait.php.expect new file mode 100644 index 000000000..74bcea9b5 --- /dev/null +++ b/hphp/test/slow/traits/sys_trait.php.expect @@ -0,0 +1,2 @@ +object(X)#1 (0) { +}