Skip to content

Commit

Permalink
Harden push-pop elimination when eliminating constants
Browse files Browse the repository at this point in the history
Ensure that LDC instructions are only eliminated when the loaded value
is a numeric or string constant. Removing other literals may remove
a potential failure. [1] lists the kind of values that can be loaded
by a LDC

[1] https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.ldc
  • Loading branch information
lrytz committed Dec 15, 2015
1 parent 80b0660 commit 55faa0d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,14 @@ class LocalOpt[BT <: BTypes](val btypes: BT) {
if (isNewForSideEffectFreeConstructor(prod)) toRemove += prod
else popAfterProd()

case LDC =>
// don't remove class literals: keep the potential NoClassDefFoundError
if (prod.asInstanceOf[LdcInsnNode].cst.isInstanceOf[Type]) popAfterProd()
else toRemove += prod
case LDC => prod.asInstanceOf[LdcInsnNode].cst match {
case _: java.lang.Integer | _: java.lang.Float | _: java.lang.Long | _: java.lang.Double | _: String =>
toRemove += prod

case _ =>
// don't remove class literals, method types, method handles: keep a potential NoClassDefFoundError
popAfterProd()
}

case NEWARRAY | ANEWARRAY =>
toRemove += prod
Expand Down

0 comments on commit 55faa0d

Please sign in to comment.