[K/N] Don't try to stack-alloc arrays of negative size

#KT-59501 Fixed
This commit is contained in:
Igor Chevdar
2023-06-19 18:25:17 +03:00
committed by Space Team
parent 95bef03d3e
commit 9e39b7ef87
@@ -1689,7 +1689,7 @@ internal object EscapeAnalysis {
val itemSize = arrayItemSizeOf(irClass)
if (itemSize != null) {
val sizeArgument = node.arguments.first().node
val arrayLength = arrayLengthOf(sizeArgument)
val arrayLength = arrayLengthOf(sizeArgument)?.takeIf { it >= 0 }
val arraySize = arraySize(itemSize, arrayLength ?: Int.MAX_VALUE)
if (arraySize <= allowedToAlloc) {
stackArrayCandidates += ArrayStaticAllocation(ptgNode, irClass, arraySize.toInt())