diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-12-15 15:55:11 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-12-15 15:55:11 +0100 |
commit | 55faa0d06fb4c2f5001626b10d0657cc337b5c37 (patch) | |
tree | c408000d7b292ca980c20872eb3d1e2e2af56a92 /src/compiler | |
parent | 80b0660efbc10325a657812720f99aff7410f0ce (diff) | |
download | scala-55faa0d06fb4c2f5001626b10d0657cc337b5c37.tar.gz scala-55faa0d06fb4c2f5001626b10d0657cc337b5c37.tar.bz2 scala-55faa0d06fb4c2f5001626b10d0657cc337b5c37.zip |
Harden push-pop elimination when eliminating constants
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
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala index a29961cdd7..1668d10da9 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala @@ -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 |