Index: llvm/lib/Transforms/Scalar/SROA.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SROA.cpp +++ llvm/lib/Transforms/Scalar/SROA.cpp @@ -2811,10 +2811,11 @@ if (BeginOffset > NewAllocaBeginOffset || EndOffset < NewAllocaEndOffset) return false; + // Length must be in range for FixedVectorType. auto *C = cast(II.getLength()); - if (C->getBitWidth() > 64) + const uint64_t Len = C->getLimitedValue(); + if (Len > std::numeric_limits::max()) return false; - const auto Len = C->getZExtValue(); auto *Int8Ty = IntegerType::getInt8Ty(NewAI.getContext()); auto *SrcTy = FixedVectorType::get(Int8Ty, Len); return canConvertValue(DL, SrcTy, AllocaTy) && Index: llvm/test/Transforms/SROA/slice-width.ll =================================================================== --- llvm/test/Transforms/SROA/slice-width.ll +++ llvm/test/Transforms/SROA/slice-width.ll @@ -4,6 +4,7 @@ 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 @@ %result = call i32 @memcpy_vec3float_helper(%S.vec3float* %tmp2) ret i32 %result } + +; Don't crash on out-of-bounds length. + +define void @PR50910() { +; CHECK-LABEL: @PR50910( +; CHECK-NEXT: [[T1:%.*]] = alloca i8, i64 1, align 8 +; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 8 [[T1]], i8 0, i64 1, i1 false) +; CHECK-NEXT: ret void +; + %t1 = alloca i8, i64 1, align 8 + call void @llvm.memset.p0i8.i64(i8* align 8 %t1, i8 0, i64 4294967296, i1 false) + ret void +}