Skip to content

Commit 2a7ed2c

Browse files
committed
[SROA] Protect against calling the alloca ptr
In case we are calling the alloca ptr directly, check that the Use is a normal operand to the call. Fortran is a funny language.
1 parent 3508d8f commit 2a7ed2c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,8 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor<SliceBuilder> {
13991399
void visitCallBase(CallBase &CB) {
14001400
// If the call operand is NoCapture ReadOnly, then we mark it as
14011401
// EscapedReadOnly.
1402-
if (CB.doesNotCapture(U->getOperandNo()) &&
1402+
if (CB.isDataOperand(U) &&
1403+
CB.doesNotCapture(U->getOperandNo()) &&
14031404
CB.onlyReadsMemory(U->getOperandNo())) {
14041405
PI.setEscapedReadOnly(&CB);
14051406
return;

llvm/test/Transforms/SROA/readonlynocapture.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,19 @@ define i32 @sixteenload() {
375375
ret i32 %a2
376376
}
377377

378+
define i32 @testcallalloca() {
379+
; CHECK-LABEL: @testcallalloca(
380+
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
381+
; CHECK-NEXT: store i32 0, ptr [[A]], align 4
382+
; CHECK-NEXT: call void [[A]]()
383+
; CHECK-NEXT: [[L1:%.*]] = load i32, ptr [[A]], align 4
384+
; CHECK-NEXT: ret i32 [[L1]]
385+
;
386+
%a = alloca i32
387+
store i32 0, ptr %a
388+
call void %a()
389+
%l1 = load i32, ptr %a
390+
ret i32 %l1
391+
}
392+
378393
declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)

0 commit comments

Comments
 (0)