<?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>143457</bug_id>
          
          <creation_ts>2015-04-06 15:53:44 -0700</creation_ts>
          <short_desc>Fix -Wparentheses warning with GCC 5 in SaturatedArithmetic.h</short_desc>
          <delta_ts>2015-04-13 09:02:54 -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>Web Template Framework</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</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>Minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Catanzaro">mcatanzaro</reporter>
          <assigned_to name="Michael Catanzaro">mcatanzaro</assigned_to>
          <cc>benjamin</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>commit-queue</cc>
    
    <cc>darin</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>zan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1083190</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-04-06 15:53:44 -0700</bug_when>
    <thetext>When building with GCC 5, I can&apos;t see any real warnings, because this buddy gets printed 3000 times [1] during compilation:

../../Source/WTF/wtf/SaturatedArithmetic.h: In function ‘bool signedAddOverflows(int32_t, int32_t, int32_t&amp;)’:
../../Source/WTF/wtf/SaturatedArithmetic.h:49:29: warning: suggest parentheses around operand of ‘!’ or change ‘&amp;’ to ‘&amp;&amp;’ or ‘!’ to ‘~’ [-Wparentheses]
     return !((ua ^ ub) &gt;&gt; 31) &amp; (uresult ^ ua) &gt;&gt; 31;
                             ^

Clang has had this same warning for a while. The warning is spurious [2], but it&apos;s a good warning so let&apos;s placate it rather than disable. Two solutions:

Add extra parentheses: return (!((ua ^ ub) &gt;&gt; 31)) &amp; (uresult ^ ua) &gt;&gt; 31;

Note that is equivalent to the original code [3].

Another option is to use &amp;&amp;:

!((ua ^ ub) &gt;&gt; 31) &amp;&amp; (uresult ^ ua) &gt;&gt; 31;

That looks better to me, since there are fewer parentheses and it avoids the confusing/unnecessary [3] mask.

[1] I just made that up, but it doesn&apos;t feel like an unreasonable guess.
[2] &amp; and &amp;&amp; both have the same precedence relative to !
[3] Provided I&apos;ve squinted at this long enough.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083194</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-04-06 16:08:48 -0700</bug_when>
    <thetext>(In reply to comment #0)
&gt; Another option is to use &amp;&amp;:
&gt; 
&gt; !((ua ^ ub) &gt;&gt; 31) &amp;&amp; (uresult ^ ua) &gt;&gt; 31;

Didn&apos;t squint hard enough; that needs more parentheses. The choices are:

(!((ua ^ ub) &gt;&gt; 31)) &amp; (uresult ^ ua) &gt;&gt; 31;

or

!((ua ^ ub) &gt;&gt; 31) &amp;&amp; ((uresult ^ ua) &gt;&gt; 31);

I think I prefer the later.



For subtraction, we currently have this:

(ua ^ ub) &gt;&gt; 31 &amp; (uresult ^ ua) &gt;&gt; 31

If we use &amp;&amp; for addition, we&apos;d want to use &amp;&amp; there as well, so it would become:

((ua ^ ub) &gt;&gt; 31) &amp;&amp; ((uresult ^ ua) &gt;&gt; 31)

That seems a bit clearer....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083296</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-04-07 05:47:44 -0700</bug_when>
    <thetext>(In reply to comment #1) 
&gt; Didn&apos;t squint hard enough; that needs more parentheses.

Squinted too hard. &gt;&gt; has higher precedence than both &amp; and &amp;&amp; so the extra parentheses are not needed. Comment #0 is correct.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083772</commentid>
    <comment_count>3</comment_count>
      <attachid>250394</attachid>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-04-08 16:54:58 -0700</bug_when>
    <thetext>Created attachment 250394
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1083774</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2015-04-08 16:56:21 -0700</bug_when>
    <thetext>Note, I only tested the change in GCC, so I&apos;m not completely sure this removes the warning if you use Clang, but I guess it does.

If this causes a performance regression we should just add extra parentheses instead.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1084708</commentid>
    <comment_count>5</comment_count>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2015-04-12 17:56:17 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; Note, I only tested the change in GCC, so I&apos;m not completely sure this
&gt; removes the warning if you use Clang, but I guess it does.
&gt; 
&gt; If this causes a performance regression we should just add extra parentheses
&gt; instead.

If a compiler has trouble with something this simple, we should fix the compiler :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1084711</commentid>
    <comment_count>6</comment_count>
      <attachid>250394</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-04-12 18:30:59 -0700</bug_when>
    <thetext>Comment on attachment 250394
Patch

Clearing flags on attachment: 250394

Committed r182676: &lt;http://trac.webkit.org/changeset/182676&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1084712</commentid>
    <comment_count>7</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-04-12 18:31:03 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1084816</commentid>
    <comment_count>8</comment_count>
      <attachid>250394</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-04-13 09:01:51 -0700</bug_when>
    <thetext>Comment on attachment 250394
Patch

Maybe &amp; rather than &amp;&amp; is what we wanted, but with the additional parentheses to make sure the shifts happen first? I guess a sufficiently high quality compiler would generate the same code for both.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1084817</commentid>
    <comment_count>9</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2015-04-13 09:02:54 -0700</bug_when>
    <thetext>I see now that Michael and Ben had this exact conversation yesterday!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>250394</attachid>
            <date>2015-04-08 16:54:58 -0700</date>
            <delta_ts>2015-04-12 18:30:59 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-143457-20150408185407.patch</filename>
            <type>text/plain</type>
            <size>2147</size>
            <attacher name="Michael Catanzaro">mcatanzaro</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTgyNTY5CmRpZmYgLS1naXQgYS9Tb3VyY2UvV1RGL0NoYW5n
ZUxvZyBiL1NvdXJjZS9XVEYvQ2hhbmdlTG9nCmluZGV4IGIwZGU0NDMzNGY3Y2RlMGU2NDQxYmZm
NTY2YWViYjViMjk3Y2Y4ZTMuLjM3NTdlYjc1Y2ZkZjA1ZGM3NDBhNzA4ZWMwZWNlYzg4MjZlNzk0
ZGQgMTAwNjQ0Ci0tLSBhL1NvdXJjZS9XVEYvQ2hhbmdlTG9nCisrKyBiL1NvdXJjZS9XVEYvQ2hh
bmdlTG9nCkBAIC0xLDMgKzEsMTcgQEAKKzIwMTUtMDQtMDggIE1pY2hhZWwgQ2F0YW56YXJvICA8
bWNhdGFuemFyb0BpZ2FsaWEuY29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