<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>122332</bug_id>
          
          <creation_ts>2013-10-04 11:18:30 -0700</creation_ts>
          <short_desc>FTL: Crash in OSRExit::convertToForward() using VirtualRegister.offset() as array index</short_desc>
          <delta_ts>2013-10-04 11:51:34 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>122336</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Saboff">msaboff</reporter>
          <assigned_to name="Michael Saboff">msaboff</assigned_to>
          <cc>fpizlo</cc>
    
    <cc>nrotem</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>936259</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2013-10-04 11:18:30 -0700</bug_when>
    <thetext>There are several instances in OSRExit::convertToForward() where we are using the offset() method on a virtual register as an array index.  The should be toLocal() calls instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936275</commentid>
    <comment_count>1</comment_count>
    <who name="Nadav Rotem">nrotem</who>
    <bug_when>2013-10-04 11:32:49 -0700</bug_when>
    <thetext>Looks Good To Me (LGTM).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936277</commentid>
    <comment_count>2</comment_count>
      <attachid>213381</attachid>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2013-10-04 11:33:56 -0700</bug_when>
    <thetext>Created attachment 213381
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936280</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2013-10-04 11:36:55 -0700</bug_when>
    <thetext>Committed r156900: &lt;http://trac.webkit.org/changeset/156900&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936287</commentid>
    <comment_count>4</comment_count>
      <attachid>213381</attachid>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-10-04 11:44:33 -0700</bug_when>
    <thetext>Comment on attachment 213381
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=213381&amp;action=review

&gt; Source/JavaScriptCore/ftl/FTLOSRExit.cpp:90
&gt; -    if (m_values[overriddenOperand.offset()].isArgument()) {
&gt; -        ExitArgument exitArgument = m_values[overriddenOperand.offset()].exitArgument();
&gt; +    if (m_values[overriddenOperand.toLocal()].isArgument()) {
&gt; +        ExitArgument exitArgument = m_values[overriddenOperand.toLocal()].exitArgument();
&gt;          arguments[exitArgument.argument()] = value.value();
&gt; -        m_values[overriddenOperand.offset()] = ExitValue::exitArgument(
&gt; +        m_values[overriddenOperand.toLocal()] = ExitValue::exitArgument(

I think that this is still wrong.  m_values is an Operands&lt;&gt;, which can be indexed in two ways:

Operands&lt;&gt;::operator[]: this is only meant for iterating over all of the entries, and the index is meaningless. it is neither the offset nor the local - it&apos;s nothing.  Hence this code was totally wrong to begin with for using m_values[...], and only worked by accident.

Operands&lt;&gt;::operand(): this takes a VirtualRegister.

There are other indexing modes like Operands&lt;&gt;::local() and Operands&lt;&gt;::argument(), but those are less useful since usually in the DFG and FTL we don&apos;t know if something is a local or an argument and we don&apos;t really care.

In this code, overriddenOperand could be an argument, maybe if you did something like:

function foo(x) { x = x | 0 }

I don&apos;t know if you&apos;ll actually get a MovHint into the argument here, but that would be valid IR for this byte code so we should be able to handle it.

So, the correct thing to do here is to say:

if (m_values.operand(overriddenOperand).isArgument()) { ...

And:

m_values.operand(overriddenOperand) = ExitValue::exitArgument( ...

That way, it&apos;ll handle both locals and arguments and there will be no confusion over what to use as indices.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936288</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2013-10-04 11:46:27 -0700</bug_when>
    <thetext>I&apos;ll make the changes that Phil suggests and submit a new patch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936290</commentid>
    <comment_count>6</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-10-04 11:47:35 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; I&apos;ll make the changes that Phil suggests and submit a new patch.

Can you fix it in: https://bugs.webkit.org/show_bug.cgi?id=122336</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936291</commentid>
    <comment_count>7</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2013-10-04 11:47:50 -0700</bug_when>
    <thetext>(In reply to comment #6)
&gt; (In reply to comment #5)
&gt; &gt; I&apos;ll make the changes that Phil suggests and submit a new patch.
&gt; 
&gt; Can you fix it in: https://bugs.webkit.org/show_bug.cgi?id=122336

(or dup appropriately if you already created your own bug.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>936294</commentid>
    <comment_count>8</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2013-10-04 11:51:25 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; (In reply to comment #6)
&gt; &gt; (In reply to comment #5)
&gt; &gt; &gt; I&apos;ll make the changes that Phil suggests and submit a new patch.
&gt; &gt; 
&gt; &gt; Can you fix it in: https://bugs.webkit.org/show_bug.cgi?id=122336
&gt; 
&gt; (or dup appropriately if you already created your own bug.)

I&apos;ll fix it in 122336.  Testing now.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>213381</attachid>
            <date>2013-10-04 11:33:56 -0700</date>
            <delta_ts>2013-10-04 11:44:33 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>122332.patch</filename>
            <type>text/plain</type>
            <size>2172</size>
            <attacher name="Michael Saboff">msaboff</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTU2ODk2KQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE2IEBA
CisyMDEzLTEwLTA0ICBNaWNoYWVsIFNhYm9mZiAgPG1zYWJvZmZAYXBwbGUuY29tPgorCisgICAg
ICAgIEZUTDogQ3Jhc2ggaW4gT1NSRXhpdDo6Y29udmVydFRvRm9yd2FyZCgpIHVzaW5nIFZpcnR1
YWxSZWdpc3Rlci5vZmZzZXQoKSBhcyBhcnJheSBpbmRleAorICAgICAgICBodHRwczovL2J1Z3Mu
d2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTIyMzMyCisKKyAgICAgICAgUmV2aWV3ZWQgYnkg
Tk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgQ2hhbmdlZCB0aGUgdXNlcyBvZiAub2Zmc2V0KCks
IHdoaWNoIHJldHVybnMgYSBuZWdhdGl2ZSBudW1iZXIgZm9yIGxvY2FscywgdG8gYmUKKyAgICAg
ICAgdG9Mb2NhbCgpIHdoaWNoIHJldHVybnMgYSBsb2NhbCdzIG9yZGluYWwgbnVtYmVyLgorCisg
ICAgICAgICogZnRsL0ZUTE9TUkV4aXQuY3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AgICBpZiAobV92YWx1ZXNbb3ZlcnJpZGRlbk9w
ZXJhbmQudG9Mb2NhbCgpXS5pc0FyZ3VtZW50KCkpIHsKKyAgICAgICAgRXhpdEFyZ3VtZW50IGV4
aXRBcmd1bWVudCA9IG1fdmFsdWVzW292ZXJyaWRkZW5PcGVyYW5kLnRvTG9jYWwoKV0uZXhpdEFy
Z3VtZW50KCk7CiAgICAgICAgIGFyZ3VtZW50c1tleGl0QXJndW1lbnQuYXJndW1lbnQoKV0gPSB2
YWx1ZS52YWx1ZSgpOwotICAgICAgICBtX3ZhbHVlc1tvdmVycmlkZGVuT3BlcmFuZC5vZmZzZXQo
KV0gPSBFeGl0VmFsdWU6OmV4aXRBcmd1bWVudCgKKyAgICAgICAgbV92YWx1ZXNbb3ZlcnJpZGRl
bk9wZXJhbmQudG9Mb2NhbCgpXSA9IEV4aXRWYWx1ZTo6ZXhpdEFyZ3VtZW50KAogICAgICAgICAg
ICAgZXhpdEFyZ3VtZW50LndpdGhGb3JtYXQodmFsdWUuZm9ybWF0KCkpKTsKICAgICAgICAgcmV0
dXJuOwogICAgIH0KICAgICAKICAgICB1bnNpZ25lZCBhcmd1bWVudCA9IGFyZ3VtZW50cy5zaXpl
KCk7CiAgICAgYXJndW1lbnRzLmFwcGVuZCh2YWx1ZS52YWx1ZSgpKTsKLSAgICBtX3ZhbHVlc1tt
X2xhc3RTZXRPcGVyYW5kLm9mZnNldCgpXSA9IEV4aXRWYWx1ZTo6ZXhpdEFyZ3VtZW50KAorICAg
IG1fdmFsdWVzW21fbGFzdFNldE9wZXJhbmQudG9Mb2NhbCgpXSA9IEV4aXRWYWx1ZTo6ZXhpdEFy
Z3VtZW50KAogICAgICAgICBFeGl0QXJndW1lbnQodmFsdWUuZm9ybWF0KCksIGFyZ3VtZW50KSk7
CiB9CiAK
</data>
<flag name="review"
          id="235732"
          type_id="1"
          status="-"
          setter="fpizlo"
    />
          </attachment>
      

    </bug>

</bugzilla>