[llvm-bugs] [Bug 32098] New: Life time issue with const reference to temporary
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Feb 28 19:18:31 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=32098
Bug ID: 32098
Summary: Life time issue with const reference to temporary
Product: clang
Version: 4.0
Hardware: All
OS: All
Status: NEW
Severity: release blocker
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: stevenwu at apple.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170301/9ff51896/attachment.html>
More information about the llvm-bugs
mailing list