Skip to content

Commit 1bdfa97

Browse files
author
Filip Pizlo
committed
DFG::IntegerCheckCombiningPhase's wrap-around check shouldn't trigger C++ undef behavior on wrap-around
https://bugs.webkit.org/show_bug.cgi?id=143532 Reviewed by Gavin Barraclough. Oh the irony! We were protecting an optimization that only worked if there was no wrap-around in JavaScript. But the C++ code had wrap-around, which is undef in C++. So, if the compiler was smart enough, our compiler would think that there never was wrap-around. This fixes a failure in stress/tricky-array-boiunds-checks.js when JSC is compiled with bleeding-edge clang. * dfg/DFGIntegerCheckCombiningPhase.cpp: (JSC::DFG::IntegerCheckCombiningPhase::isValid): Canonical link: https://commits.webkit.org/161560@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182562 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent c308ed7 commit 1bdfa97

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

Makefile.shared

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ifneq (,$(ARCHS))
1212
XCODE_OPTIONS += ONLY_ACTIVE_ARCH=NO
1313
endif
1414

15+
XCODE_OPTIONS += TOOLCHAINS=com.apple.dt.toolchain.OSX10_11
16+
1517
DEFAULT_VERBOSITY := $(shell defaults read org.webkit.BuildConfiguration BuildTranscriptVerbosity 2>/dev/null || echo "default")
1618
VERBOSITY ?= $(DEFAULT_VERBOSITY)
1719

Source/JavaScriptCore/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2015-04-08 Filip Pizlo <fpizlo@apple.com>
2+
3+
DFG::IntegerCheckCombiningPhase's wrap-around check shouldn't trigger C++ undef behavior on wrap-around
4+
https://bugs.webkit.org/show_bug.cgi?id=143532
5+
6+
Reviewed by Gavin Barraclough.
7+
8+
Oh the irony! We were protecting an optimization that only worked if there was no wrap-around in JavaScript.
9+
But the C++ code had wrap-around, which is undef in C++. So, if the compiler was smart enough, our compiler
10+
would think that there never was wrap-around.
11+
12+
This fixes a failure in stress/tricky-array-boiunds-checks.js when JSC is compiled with bleeding-edge clang.
13+
14+
* dfg/DFGIntegerCheckCombiningPhase.cpp:
15+
(JSC::DFG::IntegerCheckCombiningPhase::isValid):
16+
117
2015-04-07 Michael Saboff <msaboff@apple.com>
218

319
Lazily initialize LogToSystemConsole flag to reduce memory usage

Source/JavaScriptCore/dfg/DFGIntegerCheckCombiningPhase.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,17 @@ class IntegerCheckCombiningPhase : public Phase {
355355
return false;
356356

357357
switch (key.m_kind) {
358-
case ArrayBounds:
359-
return (range.m_maxBound - range.m_minBound) >= 0;
358+
case ArrayBounds: {
359+
// Have to do this carefully because C++ compilers are too smart. But all we're really doing is detecting if
360+
// the difference between the bounds is 2^31 or more. If it was, then we'd have to worry about wrap-around.
361+
// The way we'd like to write this expression is (range.m_maxBound - range.m_minBound) >= 0, but that is a
362+
// signed subtraction and compare, which allows the C++ compiler to do anything it wants in case of
363+
// wrap-around.
364+
uint32_t maxBound = range.m_maxBound;
365+
uint32_t minBound = range.m_minBound;
366+
uint32_t unsignedDifference = maxBound - minBound;
367+
return !(unsignedDifference >> 31);
368+
}
360369

361370
default:
362371
return true;

0 commit comments

Comments
 (0)