<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - llvm.launder.invariant.group results in miscompile of store-to-load forwarding case"
   href="https://bugs.llvm.org/show_bug.cgi?id=37458">37458</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm.launder.invariant.group results in miscompile of store-to-load forwarding case
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>piotr.padlewski@gmail.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:

struct A { virtual void f(); int n; };

int h() {
    A a;
    a.n = 42;
    return __builtin_launder(&a)->n;
}

To reproduce:

 * Apply <a href="https://reviews.llvm.org/D40218">https://reviews.llvm.org/D40218</a> to clang sources (you'll need to
replace CreateInvariantGroupBarrier with CreateLaunderInvariantGroup in
CGBuiltin.cpp to get it to compile)
 * Build clang and compile the above sources with -O2 -fstrict-vtable-pointers

This should compile to 'ret i32 42'. But it compiles to 'ret i32 undef'. (Also,
a dead call to 'llvm.launder.invariant.group' is left behind.)


IR testcase (miscompiled by opt -gvn):


%struct.A = type <{ i8*, i8 }>

define i8 @_Z1hv() {
entry:
  %a = alloca %struct.A, align 8
  %0 = bitcast %struct.A* %a to i8*
  %n = getelementptr inbounds %struct.A, %struct.A* %a, i64 0, i32 1
  store i8 42, i8* %n
  %p = call i8* @llvm.launder.invariant.group.p0i8(i8* nonnull %0)
  %n1 = getelementptr inbounds i8, i8* %p, i64 8
  %np = bitcast i8* %n1 to i8*
  %v = load i8, i8* %np
  ret i8 %v
}

declare i8* @llvm.launder.invariant.group.p0i8(i8*)</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>