Skip to content

Commit

Permalink
Fix frame types merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Saloed committed Nov 1, 2024
1 parent 1e40a12 commit f47e660
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,33 @@ private fun typeLub(first: TypeName, second: TypeName): TypeName {

if (first == TOP || second == TOP) return TOP

if (first == NULL) {
return if (second.isPrimitive) TOP else second
if (first.isPrimitive) {
return primitiveTypeLub(first, second)
}

if (second == NULL) {
return if (first.isPrimitive) TOP else first
if (second.isPrimitive) {
return primitiveTypeLub(second, first)
}

if (first.isPrimitive || second.isPrimitive) {
if (first.typeName == PredefinedPrimitives.Int) {
return second
}
return OBJECT_TYPE_NAME
}

if (second.typeName == PredefinedPrimitives.Int) {
return first
}
private fun primitiveTypeLub(primitiveType: TypeName, other: TypeName): TypeName {
if (primitiveType == NULL) {
return if (other.isPrimitive) TOP else other
}

return TOP
if (!other.isPrimitive) return TOP

if (primitiveType.typeName == PredefinedPrimitives.Int) {
return other
}

return OBJECT_TYPE_NAME
if (other.typeName == PredefinedPrimitives.Int) {
return primitiveType
}

return TOP

Check warning on line 246 in jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt#L246

Added line #L246 was not covered by tests
}

private fun List<*>?.parseLocals(): Array<TypeName?> {
Expand Down Expand Up @@ -1536,12 +1542,11 @@ class RawInstListBuilder(
@Suppress("UNCHECKED_CAST")
return mergeWithPresentFrames(frames as Map<AbstractInsnNode, Frame>, curInsn, localTypes, stackTypes)
} else {
return mergeWithMissedFrames(frames, curInsn, localTypes, stackTypes)
return mergeWithMissedFrames(curInsn, localTypes, stackTypes)
}
}

private fun mergeWithMissedFrames(
frames: Map<AbstractInsnNode, Frame?>,
curNode: LabelNode,
localTypes: Array<TypeName?>,
stackTypes: List<TypeName>,
Expand Down Expand Up @@ -1639,6 +1644,8 @@ class RawInstListBuilder(
type = typeLub(type, frameType)
}

if (type == TOP) return TOP

// If we have several variables types for one register we have to search right type in debug info otherwise we cannot guarantee anything
val debugType = findLocalVariableWithInstruction(variable, curLabel)
?.let { Type.getType(it.desc) }
Expand Down

0 comments on commit f47e660

Please sign in to comment.