JVM IR: do not add suffix for accessors to top level functions

This only reproduced when compiling (technically incorrect) code in the
standard library, where private functions monitorEnter/monitorExit are
accessed from another file, and their names with suffixes are not
recognized as intrinsics which should be replaced by
monitorenter/monitorexit JVM bytecode instructions.
This commit is contained in:
Alexander Udalov
2019-12-27 18:03:25 +01:00
parent d6ed93b2b8
commit 3193689086
7 changed files with 42 additions and 2 deletions
@@ -51,13 +51,13 @@ class IrIntrinsicMethods(val irBuiltIns: IrBuiltIns, val symbols: JvmSymbols) {
Key(
kotlinJvmInternalUnsafe,
null,
"access\$monitorEnter\$0",
"access\$monitorEnter",
listOf(KotlinBuiltIns.FQ_NAMES.any.toSafe())
) to MonitorInstruction.MONITOR_ENTER,
Key(
kotlinJvmInternalUnsafe,
null,
"access\$monitorExit\$1",
"access\$monitorExit",
listOf(KotlinBuiltIns.FQ_NAMES.any.toSafe())
) to MonitorInstruction.MONITOR_EXIT,
Key(
@@ -459,6 +459,9 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
private fun IrFunction.accessorName(superQualifier: IrClassSymbol?): Name {
val jvmName = context.methodSignatureMapper.mapFunctionName(this)
val suffix = when {
// Accessors for top level functions never need a suffix.
isTopLevel -> ""
// The only function accessors placed on interfaces are for private functions and JvmDefault implementations.
// The two cannot clash.
parentAsClass.isJvmInterface && Visibilities.isPrivate(visibility) -> ""