mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-19 15:13:49 -04:00
[CodeExtractor] Do not extract unsafe lifetime markers
Lifetime markers which reference inputs to the extraction region are not
safe to extract. Example ('rhs' will be extracted):
```
entry:
+------------+
| x = alloca |
| y = alloca |
+------------+
/ \
lhs: rhs:
+-------------------+ +-------------------+
| lifetime_start(x) | | lifetime_start(x) |
| use(x) | | lifetime_start(y) |
| lifetime_end(x) | | use(x, y) |
| lifetime_start(y) | | lifetime_end(y) |
| use(y) | | lifetime_end(x) |
| lifetime_end(y) | +-------------------+
+-------------------+
```
Prior to extraction, the stack coloring pass sees that the slots for 'x'
and 'y' are in-use at the same time. After extraction, the coloring pass
infers that 'x' and 'y' are *not* in-use concurrently, because markers
from 'rhs' are no longer available to help decide otherwise.
This leads to a miscompile, because the stack slots actually are in-use
concurrently in the extracted function.
Fix this by moving lifetime start/end markers for memory regions defined
in the calling function around the call to the extracted function.
Fixes llvm.org/PR39671 (rdar://45939472).
Differential Revision: https://reviews.llvm.org/D55967
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350420 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -6,10 +6,14 @@
|
||||
|
||||
@g = external local_unnamed_addr global i32, align 4
|
||||
|
||||
; CHECK-LABEL: define{{.*}}@caller(
|
||||
; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %tmp.i)
|
||||
; CHECK-NEXT: call void @callee_unknown_use1.{{.*}}(i8* %tmp.i
|
||||
; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %tmp.i)
|
||||
|
||||
define i32 @callee_unknown_use1(i32 %arg) local_unnamed_addr #0 {
|
||||
; CHECK-LABEL:define{{.*}}@callee_unknown_use1.{{[0-9]}}
|
||||
; CHECK-NOT: alloca
|
||||
; CHECK: call void @llvm.lifetime
|
||||
bb:
|
||||
%tmp = alloca i8, align 4
|
||||
%tmp2 = load i32, i32* @g, align 4, !tbaa !2
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
define i32 @callee_unknown_use2(i32 %arg) local_unnamed_addr #0 {
|
||||
; CHECK-LABEL:define{{.*}}@callee_unknown_use2.{{[0-9]}}
|
||||
; CHECK-NOT: alloca
|
||||
; CHECK: call void @llvm.lifetime
|
||||
bb:
|
||||
%tmp = alloca i32, align 4
|
||||
%tmp1 = bitcast i32* %tmp to i8*
|
||||
|
||||
Reference in New Issue
Block a user