[PATCH] D58226: [InferAddressSpaces] Prevent crash on nested ConstantExpr

Joey Gouly via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 14 02:30:24 PST 2019


joey created this revision.
Herald added subscribers: llvm-commits, nhaehnle, jvesely.
Herald added a project: LLVM.

Seems like everything on `PostOrderStack` is expected to be of pointer type.


Repository:
  rL LLVM

https://reviews.llvm.org/D58226

Files:
  lib/Transforms/Scalar/InferAddressSpaces.cpp
  test/Transforms/InferAddressSpaces/AMDGPU/infer-address-space.ll


Index: test/Transforms/InferAddressSpaces/AMDGPU/infer-address-space.ll
===================================================================
--- test/Transforms/InferAddressSpaces/AMDGPU/infer-address-space.ll
+++ test/Transforms/InferAddressSpaces/AMDGPU/infer-address-space.ll
@@ -168,6 +168,15 @@
   ret void
 }
 
+; CHECK-LABEL: @select_bug(
+; CHECK: %add.ptr157 = getelementptr inbounds <2 x i64>, <2 x i64>* undef, i64 select (i1 icmp ne (i32* inttoptr (i64 4873 to i32*), i32* null), i64 73, i64 93)
+; CHECK: %cmp169 = icmp uge <2 x i64>* undef, %add.ptr157
+define amdgpu_kernel void @select_bug() #0 {
+  %add.ptr157 = getelementptr inbounds <2 x i64>, <2 x i64>* undef, i64 select (i1 icmp ne (i32* inttoptr (i64 4873 to i32*), i32* null), i64 73, i64 93)
+  %cmp169 = icmp uge <2 x i64>* undef, %add.ptr157
+  unreachable
+}
+
 declare void @llvm.amdgcn.s.barrier() #1
 declare void @use(float) #0
 
Index: lib/Transforms/Scalar/InferAddressSpaces.cpp
===================================================================
--- lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -328,7 +328,8 @@
       Operator *Op = cast<Operator>(V);
       for (unsigned I = 0, E = Op->getNumOperands(); I != E; ++I) {
         if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Op->getOperand(I))) {
-          if (isAddressExpression(*CE) && Visited.insert(CE).second)
+          if (isAddressExpression(*CE) && Visited.insert(CE).second &&
+              CE->getType()->isPointerTy())
             PostorderStack.emplace_back(CE, false);
         }
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58226.186804.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190214/34976da6/attachment.bin>


More information about the llvm-commits mailing list