From 238db716182da1ee9a14dfd89d7273d3504335f1 Mon Sep 17 00:00:00 2001 From: sschr15 Date: Tue, 17 Dec 2024 22:42:09 -0600 Subject: [PATCH] Fix potential issue with overloads --- compiler-plugin/build.gradle.kts | 2 +- .../src/main/kotlin/SkipOverflowUnderflowCheck.kt | 2 +- .../src/main/kotlin/OverflowUnderflowChecker.kt | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler-plugin/build.gradle.kts b/compiler-plugin/build.gradle.kts index 090a82c..c330bd2 100644 --- a/compiler-plugin/build.gradle.kts +++ b/compiler-plugin/build.gradle.kts @@ -83,7 +83,7 @@ allprojects { name = "AoC Utility Kotlin Compiler Plugin" description = "Adds some utilities to code, developed originally for Advent of Code solving" - url = "https://github.com/advent-of-code/" + url = "https://github.com/sschr15/advent-of-code/" developers { developer { diff --git a/compiler-plugin/runtime-components/src/main/kotlin/SkipOverflowUnderflowCheck.kt b/compiler-plugin/runtime-components/src/main/kotlin/SkipOverflowUnderflowCheck.kt index c67022b..2996271 100644 --- a/compiler-plugin/runtime-components/src/main/kotlin/SkipOverflowUnderflowCheck.kt +++ b/compiler-plugin/runtime-components/src/main/kotlin/SkipOverflowUnderflowCheck.kt @@ -1,4 +1,4 @@ -package sschr15.aoc.annotations +package com.sschr15.aoc.annotations /** * Marks an expression to skip overflow and underflow checks. diff --git a/compiler-plugin/src/main/kotlin/OverflowUnderflowChecker.kt b/compiler-plugin/src/main/kotlin/OverflowUnderflowChecker.kt index 014297c..00b2c78 100644 --- a/compiler-plugin/src/main/kotlin/OverflowUnderflowChecker.kt +++ b/compiler-plugin/src/main/kotlin/OverflowUnderflowChecker.kt @@ -37,6 +37,10 @@ class OverflowUnderflowChecker(private val context: IrPluginContext, private val "rem", ) + val singleArgumentTypeChecks = setOf( + "inc", "dec", "unaryMinus", "abs", + ) + val intConversions = setOf("toFloat") val longConversions = setOf("toInt", "toDouble", "toFloat") val absoluteValueName = Name.special("") @@ -112,8 +116,11 @@ class OverflowUnderflowChecker(private val context: IrPluginContext, private val val primitiveType = expression.type.getPrimitiveType() ?: return super.visitCall(expression) if (primitiveType != PrimitiveType.INT && primitiveType != PrimitiveType.LONG) return super.visitCall(expression) if (expression.symbol.owner.name.asString() !in singleTypeChecks) return super.visitCall(expression) - if (expression.valueArgumentsCount == 2 && expression.getValueArgument(0)!!.type != expression.getValueArgument(1)!!.type) { - config.report(CompilerMessageSeverity.WARNING, "Arguments to arithmetic operations are of different types, skipping overflow check") + if ( + (expression.valueArgumentsCount != 2 || expression.getValueArgument(0)!!.type != expression.getValueArgument(1)!!.type) && + (expression.valueArgumentsCount != 1 || !singleArgumentTypeChecks.contains(expression.symbol.owner.name.asString())) + ) { + config.report(CompilerMessageSeverity.WARNING, "Unexpected number of arguments for ${expression.symbol.owner.name}, skipping") return super.visitCall(expression) }