[EE-IR] Add "different classloader" check to synthetic accessor lowering

This commit is contained in:
Kristoffer Andersen
2022-04-13 21:43:50 +02:00
committed by Alexander Udalov
parent f65364b191
commit aafab7800b
2 changed files with 5 additions and 3 deletions
@@ -74,7 +74,7 @@ internal class ReflectiveAccessLowering(
// Wrapper for the logic from SyntheticAccessorLowering // Wrapper for the logic from SyntheticAccessorLowering
private fun IrSymbol.isAccessible(withSuper: Boolean = false): Boolean { private fun IrSymbol.isAccessible(withSuper: Boolean = false): Boolean {
return isAccessible(context, currentScope, inlineScopeResolver, withSuper, null) return isAccessible(context, currentScope, inlineScopeResolver, withSuper, null, fromOtherClassLoader = true)
} }
// Fragments are transformed in a post-order traversal: children first, // Fragments are transformed in a post-order traversal: children first,
@@ -55,6 +55,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : FileL
currentScope: ScopeWithIr?, currentScope: ScopeWithIr?,
inlineScopeResolver: IrInlineScopeResolver, inlineScopeResolver: IrInlineScopeResolver,
withSuper: Boolean, thisObjReference: IrClassSymbol?, withSuper: Boolean, thisObjReference: IrClassSymbol?,
fromOtherClassLoader: Boolean = false
): Boolean { ): Boolean {
/// We assume that IR code that reaches us has been checked for correctness at the frontend. /// We assume that IR code that reaches us has been checked for correctness at the frontend.
/// This function needs to single out those cases where Java accessibility rules differ from Kotlin's. /// This function needs to single out those cases where Java accessibility rules differ from Kotlin's.
@@ -92,8 +93,9 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : FileL
return when { return when {
jvmVisibility == 0 /* package only */ -> samePackage jvmVisibility == 0 /* package only */ -> samePackage
jvmVisibility == Opcodes.ACC_PRIVATE -> ownerClass == scopeClassOrPackage jvmVisibility == Opcodes.ACC_PRIVATE -> ownerClass == scopeClassOrPackage
// JVM `protected`, unlike Kotlin `protected`, permits accesses from the same package. // JVM `protected`, unlike Kotlin `protected`, permits accesses from the same package,
!withSuper && samePackage -> true // provided the call is not across class loader boundaries.
!withSuper && samePackage && !fromOtherClassLoader -> true
// Super calls and cross-package protected accesses are both only possible from a subclass of the declaration // Super calls and cross-package protected accesses are both only possible from a subclass of the declaration
// owner. Also, the target of a non-static call must be assignable to the current class. This is a verification // owner. Also, the target of a non-static call must be assignable to the current class. This is a verification
// constraint: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.10.1.8 // constraint: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.10.1.8