<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 - Life time issue with const reference to temporary"
   href="https://bugs.llvm.org/show_bug.cgi?id=32098">32098</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Life time issue with const reference to temporary
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>stevenwu@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Here is the test case:
$ cat test.cpp
class A {
public:
  A(int v) { _a = v; }

  A& check() { return *this; }

  static int getV(A x) { return x._a; }
  int _a;
};

A test() {
  return A(0);
}

int main() {
  const A& x = test().check();

  int ret = A::getV(x);

  return ret;
}

$ clang++ --std=c++11 -Os test.cpp -mllvm -disable-llvm-optzns -emit-llvm -S -o
-
define i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca %class.A*, align 8
  %3 = alloca %class.A, align 4
  %4 = alloca i32, align 4
  %5 = alloca %class.A, align 4
  store i32 0, i32* %1, align 4
  %6 = bitcast %class.A** %2 to i8*
  call void @llvm.lifetime.start(i64 8, i8* %6) #5
  %7 = bitcast %class.A* %3 to i8*
  call void @llvm.lifetime.start(i64 4, i8* %7) #5
  %8 = call i32 @_Z4testv() #4
  %9 = getelementptr inbounds %class.A, %class.A* %3, i32 0, i32 0
  store i32 %8, i32* %9, align 4
  %10 = call dereferenceable(4) %class.A* @_ZN1A5checkEv(%class.A* %3) #4
  %11 = bitcast %class.A* %3 to i8*
  call void @llvm.lifetime.end(i64 4, i8* %11) #5
  store %class.A* %10, %class.A** %2, align 8, !tbaa !8
  %12 = bitcast i32* %4 to i8*
  call void @llvm.lifetime.start(i64 4, i8* %12) #5
  %13 = load %class.A*, %class.A** %2, align 8
  %14 = bitcast %class.A* %5 to i8*
  %15 = bitcast %class.A* %13 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %14, i8* %15, i64 4, i32 4, i1
false), !tbaa.struct !9
  %16 = getelementptr inbounds %class.A, %class.A* %5, i32 0, i32 0
  %17 = load i32, i32* %16, align 4
  %18 = call i32 @_ZN1A4getVES_(i32 %17) #4
  store i32 %18, i32* %4, align 4, !tbaa !6
  %19 = load i32, i32* %4, align 4, !tbaa !6
  %20 = bitcast i32* %4 to i8*
  call void @llvm.lifetime.end(i64 4, i8* %20) #5
  %21 = bitcast %class.A** %2 to i8*
  call void @llvm.lifetime.end(i64 8, i8* %21) #5
  ret i32 %19
}

The lifetime intrinsics suggests that "const A& x" dies immediately after the
expression which I am not sure if that is the correct behavior. This will cause
crashes if test and check function are not inlined.
This looks like a regression after r288563.</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>