Title: [202512] trunk/Source/_javascript_Core
- Revision
- 202512
- Author
- [email protected]
- Date
- 2016-06-27 14:36:19 -0700 (Mon, 27 Jun 2016)
Log Message
B3::Procedure::resetReachability() can create dangling references from Upsilons to Phis
https://bugs.webkit.org/show_bug.cgi?id=159165
Reviewed by Mark Lam.
You can delete an unreachable block that has a Phi but some prior block may still have an
Upsilon pointing to that Phi. This can happen if the Upsilon precedes a Check that always
exits or it can happen if we remove some successor of a block and this block had an Upsilon
for one of the removed successors. These things are valid IR even if they are not canonical.
Our policy for not-canonical-but-valid IR is that the compiler should still emit valid code
in the end.
The solution is to have Procedure::resetReachability() turn those Upsilons into Nops.
* b3/B3Procedure.cpp:
(JSC::B3::Procedure::resetReachability): Fix the bug.
* b3/B3Validate.h:
* b3/testb3.cpp:
(JSC::B3::testResetReachabilityDanglingReference): Add a test. This always crashes prior to this change.
* dfg/DFGGraph.cpp:
(JSC::DFG::Graph::killUnreachableBlocks): Add a FIXME about a possible similar bug.
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (202511 => 202512)
--- trunk/Source/_javascript_Core/ChangeLog 2016-06-27 20:59:27 UTC (rev 202511)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-06-27 21:36:19 UTC (rev 202512)
@@ -1,3 +1,27 @@
+2016-06-27 Filip Pizlo <[email protected]>
+
+ B3::Procedure::resetReachability() can create dangling references from Upsilons to Phis
+ https://bugs.webkit.org/show_bug.cgi?id=159165
+
+ Reviewed by Mark Lam.
+
+ You can delete an unreachable block that has a Phi but some prior block may still have an
+ Upsilon pointing to that Phi. This can happen if the Upsilon precedes a Check that always
+ exits or it can happen if we remove some successor of a block and this block had an Upsilon
+ for one of the removed successors. These things are valid IR even if they are not canonical.
+ Our policy for not-canonical-but-valid IR is that the compiler should still emit valid code
+ in the end.
+
+ The solution is to have Procedure::resetReachability() turn those Upsilons into Nops.
+
+ * b3/B3Procedure.cpp:
+ (JSC::B3::Procedure::resetReachability): Fix the bug.
+ * b3/B3Validate.h:
+ * b3/testb3.cpp:
+ (JSC::B3::testResetReachabilityDanglingReference): Add a test. This always crashes prior to this change.
+ * dfg/DFGGraph.cpp:
+ (JSC::DFG::Graph::killUnreachableBlocks): Add a FIXME about a possible similar bug.
+
2016-06-27 Keith Miller <[email protected]>
Add comment to Module feature in features.json
Modified: trunk/Source/_javascript_Core/b3/B3Procedure.cpp (202511 => 202512)
--- trunk/Source/_javascript_Core/b3/B3Procedure.cpp 2016-06-27 20:59:27 UTC (rev 202511)
+++ trunk/Source/_javascript_Core/b3/B3Procedure.cpp 2016-06-27 21:36:19 UTC (rev 202512)
@@ -36,6 +36,7 @@
#include "B3DataSection.h"
#include "B3Dominators.h"
#include "B3OpaqueByproducts.h"
+#include "B3PhiChildren.h"
#include "B3StackSlot.h"
#include "B3ValueInlines.h"
#include "B3Variable.h"
@@ -172,13 +173,31 @@
}
}
+ IndexSet<Value> valuesToDelete;
+
B3::resetReachability(
m_blocks,
[&] (BasicBlock* deleted) {
// Gotta delete the values in this block.
for (Value* value : *deleted)
- deleteValue(value);
+ valuesToDelete.add(value);
});
+
+ if (valuesToDelete.isEmpty())
+ return;
+
+ for (BasicBlock* block : *this) {
+ for (Value* value : *block) {
+ ASSERT(!valuesToDelete.contains(value)); // The block should have been deleted already.
+ if (UpsilonValue* upsilon = value->as<UpsilonValue>()) {
+ if (valuesToDelete.contains(upsilon->phi()))
+ upsilon->replaceWithNop();
+ }
+ }
+ }
+
+ for (Value* value : valuesToDelete.values(values()))
+ deleteValue(value);
}
void Procedure::invalidateCFG()
Modified: trunk/Source/_javascript_Core/b3/B3Validate.h (202511 => 202512)
--- trunk/Source/_javascript_Core/b3/B3Validate.h 2016-06-27 20:59:27 UTC (rev 202511)
+++ trunk/Source/_javascript_Core/b3/B3Validate.h 2016-06-27 21:36:19 UTC (rev 202512)
@@ -32,7 +32,7 @@
class Procedure;
-void validate(Procedure&, const char* dumpBefore = nullptr);
+JS_EXPORT_PRIVATE void validate(Procedure&, const char* dumpBefore = nullptr);
} } // namespace JSC::B3
Modified: trunk/Source/_javascript_Core/b3/testb3.cpp (202511 => 202512)
--- trunk/Source/_javascript_Core/b3/testb3.cpp 2016-06-27 20:59:27 UTC (rev 202511)
+++ trunk/Source/_javascript_Core/b3/testb3.cpp 2016-06-27 21:36:19 UTC (rev 202512)
@@ -44,6 +44,7 @@
#include "B3StackmapGenerationParams.h"
#include "B3SwitchValue.h"
#include "B3UpsilonValue.h"
+#include "B3Validate.h"
#include "B3ValueInlines.h"
#include "CCallHelpers.h"
#include "InitializeThreading.h"
@@ -12084,6 +12085,25 @@
reduceStrength(proc);
}
+void testResetReachabilityDanglingReference()
+{
+ Procedure proc;
+
+ BasicBlock* _one_ = proc.addBlock();
+ BasicBlock* two = proc.addBlock();
+
+ UpsilonValue* upsilon = one->appendNew<UpsilonValue>(
+ proc, Origin(), one->appendNew<Const32Value>(proc, Origin(), 42));
+ one->appendNew<ControlValue>(proc, Oops, Origin());
+
+ Value* phi = two->appendNew<Value>(proc, Phi, Int32, Origin());
+ upsilon->setPhi(phi);
+ two->appendNew<ControlValue>(proc, Oops, Origin());
+
+ proc.resetReachability();
+ validate(proc);
+}
+
// Make sure the compiler does not try to optimize anything out.
NEVER_INLINE double zero()
{
@@ -13487,6 +13507,7 @@
RUN(testSpillUseLargerThanDef());
RUN(testLateRegister());
RUN(testReduceStrengthCheckBottomUseInAnotherBlock());
+ RUN(testResetReachabilityDanglingReference());
if (tasks.isEmpty())
usage();
Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.cpp (202511 => 202512)
--- trunk/Source/_javascript_Core/dfg/DFGGraph.cpp 2016-06-27 20:59:27 UTC (rev 202511)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.cpp 2016-06-27 21:36:19 UTC (rev 202512)
@@ -754,6 +754,9 @@
void Graph::killUnreachableBlocks()
{
+ // FIXME: This probably creates dangling references from Upsilons to Phis in SSA.
+ // https://bugs.webkit.org/show_bug.cgi?id=159164
+
for (BlockIndex blockIndex = 0; blockIndex < numBlocks(); ++blockIndex) {
BasicBlock* block = this->block(blockIndex);
if (!block)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes