<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:t.p.northover@gmail.com" title="Tim Northover <t.p.northover@gmail.com>"> <span class="fn">Tim Northover</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - using optimizations yields different output"
   href="https://bugs.llvm.org/show_bug.cgi?id=40402">bug 40402</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;">Status</td>
           <td>REOPENED
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - using optimizations yields different output"
   href="https://bugs.llvm.org/show_bug.cgi?id=40402#c6">Comment # 6</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - using optimizations yields different output"
   href="https://bugs.llvm.org/show_bug.cgi?id=40402">bug 40402</a>
              from <span class="vcard"><a class="email" href="mailto:t.p.northover@gmail.com" title="Tim Northover <t.p.northover@gmail.com>"> <span class="fn">Tim Northover</span></a>
</span></b>
        <pre>Unfortunately there are more problems in the source. I probably should have
read it more thoroughly the first time but I just ran -fsanitize=undefined over
it.

This time the issue is that all objects in C and C++ can only have one type,
and must always be used as that type (or "char *", known as the "omnipotent
char"). It's not valid to access a single object through both a "uint64_t *" to
a "uint16_t *" for example.

If you need to do that kind of thing in C, the recommended solution is to
memcpy from one object to another with the desired type. The compiler is very
good at spotting that idiom and will generally turn it into the optimal code.
In C++20 there's going to be a "bit_cast<newtype>" function to make it less
clunky.

Alternatively (and this is how I verified it was the issue) both Clang and GCC
support a "-fno-strict-aliasing" option which essentially switches to a dialect
of the language without that rule.

Also, your initial malloc is wonky. -fsanitize=address points out that your
alignment step moves past the end of the object. This isn't what's causing the
problem though, just thought I'd point it out.

I'll close it again for now.</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>