[llvm] ee29a84 - DAG: Fix assert when alloca has inconsistent pointer size
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 29 08:48:54 PST 2022
Author: Matt Arsenault
Date: 2022-11-29T11:48:46-05:00
New Revision: ee29a846c622b52d82e208146a028cf866351fde
URL: https://github.com/llvm/llvm-project/commit/ee29a846c622b52d82e208146a028cf866351fde
DIFF: https://github.com/llvm/llvm-project/commit/ee29a846c622b52d82e208146a028cf866351fde.diff
LOG: DAG: Fix assert when alloca has inconsistent pointer size
Take the type from the alloca, not the type to use for allocas.
Fixes issue 59250.
Added:
llvm/test/CodeGen/AMDGPU/assert-wrong-alloca-addrspace.ll
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 380d30d9d3bc..50098e87c00b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1698,8 +1698,8 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
DenseMap<const AllocaInst*, int>::iterator SI =
FuncInfo.StaticAllocaMap.find(AI);
if (SI != FuncInfo.StaticAllocaMap.end())
- return DAG.getFrameIndex(SI->second,
- TLI.getFrameIndexTy(DAG.getDataLayout()));
+ return DAG.getFrameIndex(
+ SI->second, TLI.getValueType(DAG.getDataLayout(), AI->getType()));
}
// If this is an instruction which fast-isel has deferred, select it now.
@@ -4030,7 +4030,7 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
SDValue AllocSize = getValue(I.getArraySize());
- EVT IntPtr = TLI.getPointerTy(DAG.getDataLayout(), DL.getAllocaAddrSpace());
+ EVT IntPtr = TLI.getPointerTy(DAG.getDataLayout(), I.getAddressSpace());
if (AllocSize.getValueType() != IntPtr)
AllocSize = DAG.getZExtOrTrunc(AllocSize, dl, IntPtr);
diff --git a/llvm/test/CodeGen/AMDGPU/assert-wrong-alloca-addrspace.ll b/llvm/test/CodeGen/AMDGPU/assert-wrong-alloca-addrspace.ll
new file mode 100644
index 000000000000..a76c07842648
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/assert-wrong-alloca-addrspace.ll
@@ -0,0 +1,16 @@
+; RUN: not llc -march=amdgcn -mcpu=gfx900 -filetype=null %s 2>&1 | FileCheck
+
+; The alloca has the wrong address space and is passed to a call. The
+; FrameIndex was created with the natural 32-bit pointer type instead
+; of the declared 64-bit. Make sure we don't assert.
+
+; CHECK: LLVM ERROR: Cannot select: {{.*}}: i64 = FrameIndex<0>
+
+declare void @func(ptr)
+
+define void @main() {
+bb:
+ %alloca = alloca i32, align 4
+ call void @func(ptr %alloca)
+ ret void
+}
More information about the llvm-commits
mailing list