<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:lebedev.ri@gmail.com" title="Roman Lebedev <lebedev.ri@gmail.com>"> <span class="fn">Roman Lebedev</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Simple C program produces different output if compiled with -O1 instead of -O0"
   href="https://bugs.llvm.org/show_bug.cgi?id=44424">bug 44424</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>lebedev.ri@gmail.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Simple C program produces different output if compiled with -O1 instead of -O0"
   href="https://bugs.llvm.org/show_bug.cgi?id=44424#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Simple C program produces different output if compiled with -O1 instead of -O0"
   href="https://bugs.llvm.org/show_bug.cgi?id=44424">bug 44424</a>
              from <span class="vcard"><a class="email" href="mailto:lebedev.ri@gmail.com" title="Roman Lebedev <lebedev.ri@gmail.com>"> <span class="fn">Roman Lebedev</span></a>
</span></b>
        <pre>(In reply to Dirk Hoffmann from <a href="show_bug.cgi?id=44424#c0">comment #0</a>)
<span class="quote">> Test program: main.cpp


> #include <stdint.h>
> #include <stdio.h>

> bool foo(uint32_t x, uint32_t y)
> {
>         uint32_t z = (uint16_t)x * (uint16_t)y;</span >
This line contains UB - the multiplication does not happen in uint16_t,
but the uint16_t values are promoted to int, so this is signed overflow.

<a href="https://godbolt.org/z/wPp7Xq">https://godbolt.org/z/wPp7Xq</a>

<span class="quote">>         return z & 0x80000000;
> }

> int main(int argc, char *argv[])
> {
>         printf("%d\n", foo(0x7FFFF, 0x7FFFF));
> }



> Compiler: 

> Apple clang version 11.0.0 (clang-1100.0.33.8)
> Target: x86_64-apple-darwin18.7.0
> Thread model: posix

> Output:

> > clang -O0 main.cpp; ./a.out 
> 1

> > clang -O1 main.cpp; ./a.out 
> 0</span ></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>