[SROA] avoid crash on memset with constant expression length
authorSanjay Patel <spatel@rotateright.com>
Wed, 21 Jul 2021 19:15:47 +0000 (15:15 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 21 Jul 2021 19:20:28 +0000 (15:20 -0400)
https://llvm.org/PR50888

llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/Transforms/SROA/slice-width.ll

index 61c8d53519be4407592437cce17e08ecccb89f3c..5ec01454e5b2f2c4ec67e5cdc6103242f4753aff 100644 (file)
@@ -2789,7 +2789,7 @@ private:
 
     // If the memset has a variable size, it cannot be split, just adjust the
     // pointer to the new alloca.
-    if (!isa<Constant>(II.getLength())) {
+    if (!isa<ConstantInt>(II.getLength())) {
       assert(!IsSplit);
       assert(NewBeginOffset == BeginOffset);
       II.setDest(getNewAllocaSlicePtr(IRB, OldPtr->getType()));
index 2deef736de2582186417e03bb7c55908875697ab..a801de68217ff89e290bd473b3a3a8d849627f6f 100644 (file)
@@ -4,6 +4,7 @@ target datalayout = "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-
 
 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind
 declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
 
 ; This tests that allocas are not split into slices that are not byte width multiple
 define void @no_split_on_non_byte_width(i32) {
@@ -131,3 +132,16 @@ entry:
   %result = call i32 @memcpy_vec3float_helper(%S.vec3float* %tmp2)
   ret i32 %result
 }
+
+; Don't crash on length that is constant expression.
+
+define void @PR50888() {
+; CHECK-LABEL: @PR50888(
+; CHECK-NEXT:    [[ARRAY:%.*]] = alloca i8, align 1
+; CHECK-NEXT:    call void @llvm.memset.p0i8.i64(i8* align 1 [[ARRAY]], i8 0, i64 ptrtoint (void ()* @PR50888 to i64), i1 false)
+; CHECK-NEXT:    ret void
+;
+  %array = alloca i8
+  call void @llvm.memset.p0i8.i64(i8* align 16 %array, i8 0, i64 ptrtoint (void ()* @PR50888 to i64), i1 false)
+  ret void
+}