Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit f632da1

Browse files
committed
Merging r309930:
------------------------------------------------------------------------ r309930 | sdardis | 2017-08-03 02:38:46 -0700 (Thu, 03 Aug 2017) | 19 lines [SelectionDAG] Resolve PR33978. rL306209 taught SelectionDAG how to add the dereferenceable flag when expanding memcpy and memmove. The fix however contained a nit where the offset + size was constructed as an APInt of PointerSize rather than PointerSizeInBits. This lead to isDereferenceableAndAlignedPointer() get truncated values or values which would be sign extended within that function leading to incorrect results. Thanks to Alex Crichton for reporting the issue! This resolves PR33978. Reviewers: inouehrs Differential Revision: https://reviews.llvm.org/D36236 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@309956 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6db41ec commit f632da1

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/CodeGen/MachineInstr.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,8 @@ bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C,
578578
if (BasePtr == nullptr)
579579
return false;
580580

581-
return isDereferenceableAndAlignedPointer(BasePtr, 1,
582-
APInt(DL.getPointerSize(),
583-
Offset + Size),
584-
DL);
581+
return isDereferenceableAndAlignedPointer(
582+
BasePtr, 1, APInt(DL.getPointerSizeInBits(), Offset + Size), DL);
585583
}
586584

587585
/// getConstantPool - Return a MachinePointerInfo record that refers to the

test/CodeGen/Mips/pr33978.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -march=mips -mcpu=mips32r2 < %s -o /dev/null
2+
3+
; Test that SelectionDAG does not crash during DAGCombine when two pointers
4+
; to the stack match with differing bases and offsets when expanding memcpy.
5+
; This could result in one of the pointers being considered dereferenceable
6+
; and other not.
7+
8+
define void @foo(i8*) {
9+
start:
10+
%a = alloca [22 x i8]
11+
%b = alloca [22 x i8]
12+
%c = bitcast [22 x i8]* %a to i8*
13+
%d = getelementptr inbounds [22 x i8], [22 x i8]* %b, i32 0, i32 2
14+
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %c, i8* %d, i32 20, i32 1, i1 false)
15+
%e = getelementptr inbounds [22 x i8], [22 x i8]* %b, i32 0, i32 6
16+
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %e, i32 12, i32 1, i1 false)
17+
ret void
18+
}
19+
20+
declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)

0 commit comments

Comments
 (0)