From dfbf27d243bc83e97de8e8825fff0c0a8504b713 Mon Sep 17 00:00:00 2001 From: Jordan DeLong Date: Tue, 14 May 2013 14:08:39 -0700 Subject: [PATCH] Fix a bug with null constants We end up with uninit nulls in the repo for unit constants. In RepoAuthoritative mode, we will use m_type == KindOfUninit during constant lookup to decide whether to cast TypedValue::m_data.pref to a ConstantInfo*, and then call a function pointer that it contains. (We should probably also clean that up to not cast RefData*'s to ConstantInfo*'s, but I left that out of this diff.) --- hphp/compiler/analysis/emitter.cpp | 3 +++ hphp/runtime/vm/unit.cpp | 1 + hphp/test/quick/null_constant.php | 2 ++ hphp/test/quick/null_constant.php.expect | 0 4 files changed, 6 insertions(+) create mode 100644 hphp/test/quick/null_constant.php create mode 100644 hphp/test/quick/null_constant.php.expect diff --git a/hphp/compiler/analysis/emitter.cpp b/hphp/compiler/analysis/emitter.cpp index 55232cefc..49f81af61 100644 --- a/hphp/compiler/analysis/emitter.cpp +++ b/hphp/compiler/analysis/emitter.cpp @@ -1686,6 +1686,9 @@ void EmitterVisitor::visit(FileScopePtr file) { if (func->isSimpleDefine(&name, &tv)) { UnitMergeKind k = func->isDefineWithoutImpl(ar) ? UnitMergeKindPersistentDefine : UnitMergeKindDefine; + if (tv.m_type == KindOfUninit) { + tv.m_type = KindOfNull; + } m_ue.pushMergeableDef(k, name, tv); visit(s); continue; diff --git a/hphp/runtime/vm/unit.cpp b/hphp/runtime/vm/unit.cpp index edf4ccfda..1c6edefd1 100644 --- a/hphp/runtime/vm/unit.cpp +++ b/hphp/runtime/vm/unit.cpp @@ -1273,6 +1273,7 @@ void Unit::mergeImpl(void* tcbase, UnitMergeInfo* mi) { Stats::inc(Stats::UnitMerge_mergeable_define); StringData* name = (StringData*)((char*)obj - (int)k); auto* v = (TypedValueAux*)mi->mergeableData(ix + 1); + assert(v->m_type != KindOfUninit); mergeCns(getDataRef(tcbase, v->cacheHandle()), v, name); ix += 1 + sizeof(*v) / sizeof(void*); obj = mi->mergeableObj(ix); diff --git a/hphp/test/quick/null_constant.php b/hphp/test/quick/null_constant.php new file mode 100644 index 000000000..3805438ea --- /dev/null +++ b/hphp/test/quick/null_constant.php @@ -0,0 +1,2 @@ +