diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt index 0235d143cfa..6d09a966bf5 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt @@ -734,6 +734,14 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va } } + private fun receivePointedArgument(variable: LLVMSingleValue, pointer: Int): LLVMSingleValue { + var currentVariable = variable + while (currentVariable.pointer > pointer) { + currentVariable = codeBuilder.receiveNativeValue(variable) + } + return currentVariable + } + private fun addPrimitiveBinaryOperation(operator: IElementType, referenceName: KtSimpleNameExpression?, firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMVariable { val firstNativeOp = codeBuilder.receiveNativeValue(firstOp) val secondNativeOp = codeBuilder.receiveNativeValue(secondOp) @@ -746,14 +754,36 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va KtTokens.LTEQ -> firstOp.type!!.operatorLeq(firstNativeOp, secondNativeOp) KtTokens.GTEQ -> firstOp.type!!.operatorGeq(firstNativeOp, secondNativeOp) KtTokens.EQEQ -> - if ((firstOp.type is LLVMReferenceType) && (secondOp.type !is LLVMReferenceType)) - firstOp.type!!.operatorEq(firstNativeOp, secondOp) + if (firstOp.type is LLVMReferenceType) + if (secondOp.type is LLVMReferenceType) { + val firstPointedArgument = receivePointedArgument(firstOp, 1) + val secondPointedArgument = receivePointedArgument(secondOp, 1) + firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument) + } else + firstOp.type!!.operatorEq(firstNativeOp, secondOp) else firstOp.type!!.operatorEq(firstNativeOp, secondNativeOp) - KtTokens.EQEQEQ -> - firstOp.type!!.operatorEq(firstNativeOp, secondNativeOp) - KtTokens.EXCLEQ -> firstOp.type!!.operatorNeq(firstNativeOp, secondNativeOp) - KtTokens.EXCLEQEQEQ -> firstOp.type!!.operatorNeq(firstNativeOp, secondNativeOp) + KtTokens.EQEQEQ -> { + val firstPointedArgument = receivePointedArgument(firstOp, 1) + val secondPointedArgument = receivePointedArgument(secondOp, 1) + firstOp.type!!.operatorEq(firstPointedArgument, secondPointedArgument) + } + KtTokens.EXCLEQ -> { + if (firstOp.type is LLVMReferenceType) + if (secondOp.type is LLVMReferenceType) { + val firstPointedArgument = receivePointedArgument(firstOp, 1) + val secondPointedArgument = receivePointedArgument(secondOp, 1) + firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument) + } else + firstOp.type!!.operatorNeq(firstNativeOp, secondOp) + else + firstOp.type!!.operatorNeq(firstNativeOp, secondNativeOp) + } + KtTokens.EXCLEQEQEQ -> { + val firstPointedArgument = receivePointedArgument(firstOp, 1) + val secondPointedArgument = receivePointedArgument(secondOp, 1) + firstOp.type!!.operatorNeq(firstPointedArgument, secondPointedArgument) + } KtTokens.EQ -> { if (secondOp.type is LLVMNullType) { val result = codeBuilder.getNewVariable(firstOp.type!!, firstOp.pointer) diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMVoidType.kt b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMVoidType.kt index 79a6a8a2097..6a63e9f929a 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMVoidType.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/llvm/types/LLVMVoidType.kt @@ -9,6 +9,10 @@ class LLVMVoidType() : LLVMType() { override fun mangle() = "" override val typename = "void" + override fun equals(other: Any?): Boolean { + return other is LLVMVoidType + } + override fun hashCode() = typename.hashCode() diff --git a/translator/src/test/kotlin/tests/input/referential_equality_2.txt b/translator/src/test/kotlin/tests/input/referential_equality_2.txt new file mode 100644 index 00000000000..1312315a8b2 --- /dev/null +++ b/translator/src/test/kotlin/tests/input/referential_equality_2.txt @@ -0,0 +1,2 @@ +referential_equality_2_EQ_master() == 1 +referential_equality_2_NEQ_master() == 1 diff --git a/translator/src/test/kotlin/tests/kotlin/referential_equality_2.kt b/translator/src/test/kotlin/tests/kotlin/referential_equality_2.kt new file mode 100644 index 00000000000..2884645fe7f --- /dev/null +++ b/translator/src/test/kotlin/tests/kotlin/referential_equality_2.kt @@ -0,0 +1,28 @@ +class referential_equality_2_A + +fun referential_equality_2_build(): referential_equality_2_A { + return referential_equality_2_A() +} + +fun referential_equality_2_EQ_slave(second_msg: referential_equality_2_A): Int { + if (second_msg == referential_equality_2_build()) { + return 0 + } + return 1 +} + +fun referential_equality_2_NEQ_slave(second_msg: referential_equality_2_A): Int { + if (second_msg != referential_equality_2_build()) { + return 1 + } + return 0 +} + + +fun referential_equality_2_EQ_master(): Int { + return referential_equality_2_EQ_slave(referential_equality_2_build()) +} + +fun referential_equality_2_NEQ_master(): Int { + return referential_equality_2_NEQ_slave(referential_equality_2_build()) +}