Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
93e6135
Kotlin: add 2.4.20-RC artifacts
andersfugmann Aug 26, 2026
c1b4fe6
Kotlin: address KT-85816
andersfugmann Aug 26, 2026
0724caf
Kotlin: address KT-86046
andersfugmann Aug 26, 2026
96ac5ba
Kotlin: preserve generated forwarder locations
andersfugmann Aug 26, 2026
8b8b961
Kotlin: enable 2.4.20-RC support
andersfugmann Aug 26, 2026
f146aa6
Kotlin: make 2.4.20-RC the test default
andersfugmann Aug 26, 2026
b9c81d5
Kotlin: document preliminary 2.4.20-RC support
andersfugmann Aug 26, 2026
63553e3
Kotlin: support 2.4.20-RC2
andersfugmann Aug 28, 2026
2f4571b
Kotlin: cover full value class extraction
andersfugmann Aug 28, 2026
06042b1
Kotlin: cover name-based destructuring
andersfugmann Aug 28, 2026
3d99697
Kotlin: expose missing context parameters
andersfugmann Aug 28, 2026
2942d70
Kotlin: extract context parameters and arguments
andersfugmann Aug 28, 2026
05357c2
Kotlin: cover context parameter setters
andersfugmann Aug 28, 2026
8595a36
Kotlin: cover collection literal extraction
andersfugmann Aug 28, 2026
7015661
Kotlin: cover companion blocks and extensions
andersfugmann Aug 28, 2026
dedba97
Kotlin: cover invokedynamic when extraction
andersfugmann Aug 28, 2026
aa583f8
Kotlin: keep full value class coverage focused
andersfugmann Aug 28, 2026
701a005
Kotlin: assign stable context parameter indices
andersfugmann Aug 28, 2026
01235a2
Kotlin: gate full value class coverage
andersfugmann Aug 31, 2026
b514ee0
Kotlin: gate name-based destructuring coverage
andersfugmann Aug 31, 2026
0778371
Kotlin: gate context parameter coverage
andersfugmann Aug 31, 2026
a0cf379
Kotlin: gate collection literal coverage
andersfugmann Aug 31, 2026
131ef8e
Kotlin: gate companion extension coverage
andersfugmann Aug 31, 2026
8630d5a
Kotlin: gate invokedynamic when coverage
andersfugmann Aug 31, 2026
b0fab01
Kotlin: extract context parameters from 2.2.20
andersfugmann Aug 31, 2026
44f0616
Kotlin: stabilise implicit context argument locations
andersfugmann Aug 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ use_repo(
"kotlin-compiler-2.3.0",
"kotlin-compiler-2.3.20",
"kotlin-compiler-2.4.0",
"kotlin-compiler-2.4.20-RC2",
"kotlin-compiler-embeddable-1.8.0",
"kotlin-compiler-embeddable-1.9.0-Beta",
"kotlin-compiler-embeddable-1.9.20-Beta",
Expand All @@ -288,6 +289,7 @@ use_repo(
"kotlin-compiler-embeddable-2.3.0",
"kotlin-compiler-embeddable-2.3.20",
"kotlin-compiler-embeddable-2.4.0",
"kotlin-compiler-embeddable-2.4.20-RC2",
"kotlin-stdlib-1.8.0",
"kotlin-stdlib-1.9.0-Beta",
"kotlin-stdlib-1.9.20-Beta",
Expand All @@ -300,6 +302,7 @@ use_repo(
"kotlin-stdlib-2.3.0",
"kotlin-stdlib-2.3.20",
"kotlin-stdlib-2.4.0",
"kotlin-stdlib-2.4.20-RC2",
)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
Expand Down
3 changes: 2 additions & 1 deletion docs/codeql/reusables/supported-versions-compilers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Java,"Java 7 to 26 [5]_","javac (OpenJDK and Oracle JDK),

Eclipse compiler for Java (ECJ) [6]_",``.java``
Kotlin,"Kotlin 1.8.0 to 2.4.1\ *x*","kotlinc",``.kt``
Kotlin [13]_,"Kotlin 1.8.0 to 2.4.20-RC2","kotlinc",``.kt``
JavaScript,ECMAScript 2022 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhtm``, ``.xhtml``, ``.vue``, ``.hbs``, ``.ejs``, ``.njk``, ``.json``, ``.yaml``, ``.yml``, ``.raml``, ``.xml`` [7]_"
Python [8]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14",Not applicable,``.py``
Ruby,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"
Expand All @@ -43,3 +43,4 @@
.. [10] Support for the analysis of Swift requires macOS.
.. [11] Embedded Swift is not supported.
.. [12] TypeScript analysis is performed by running the JavaScript extractor with TypeScript enabled. This is the default.
.. [13] Support for Kotlin 2.4.20-RC2 is preliminary.
33 changes: 31 additions & 2 deletions java/kotlin-extractor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ _compiler_plugin_registrar_service_source = "src/main/resources/META-INF/service

_compiler_plugin_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"

_component_registrar_service_source = "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"

_component_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"

py_binary(
name = "generate_dbscheme",
srcs = ["generate_dbscheme.py"],
Expand All @@ -68,14 +72,22 @@ _resources = [
r[len("src/main/resources/"):],
)
for r in glob(["src/main/resources/**"])
if r != _compiler_plugin_registrar_service_source
if r not in (
_compiler_plugin_registrar_service_source,
_component_registrar_service_source,
)
]

_compiler_plugin_registrar_service = (
_compiler_plugin_registrar_service_source,
_compiler_plugin_registrar_service_target,
)

_component_registrar_service = (
_component_registrar_service_source,
_component_registrar_service_target,
)

kt_javac_options(
name = "javac-options",
release = "8",
Expand All @@ -93,7 +105,11 @@ kt_javac_options(
"kotlin.RequiresOptIn",
"org.jetbrains.kotlin.ir.symbols.%s" %
("IrSymbolInternals" if version_less(v, "2.0.0") else "UnsafeDuringIrConstructionAPI"),
] + ([] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]),
] + (
[] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]
) + (
[] if version_less(v, "2.4.20") else ["org.jetbrains.kotlin.K1Deprecation"]
),
x_suppress_version_warnings = True,
),
# * extractor.name is different for each version, so we need to put it in different output dirs
Expand All @@ -103,6 +119,8 @@ kt_javac_options(
name = "resources-%s" % v,
srcs = [src for src, _ in _resources] + (
[_compiler_plugin_registrar_service[0]] if not version_less(v, "2.4.0") else []
) + (
[_component_registrar_service[0]] if version_less(v, "2.4.20") else []
),
outs = [
"%s/com/github/codeql/extractor.name" % v,
Expand All @@ -114,6 +132,11 @@ kt_javac_options(
v,
_compiler_plugin_registrar_service[1],
)] if not version_less(v, "2.4.0") else []
) + (
["%s/%s" % (
v,
_component_registrar_service[1],
)] if version_less(v, "2.4.20") else []
),
cmd = "\n".join([
"echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v),
Expand All @@ -126,6 +149,12 @@ kt_javac_options(
v,
_compiler_plugin_registrar_service[1],
)] if not version_less(v, "2.4.0") else []
) + (
["cp $(execpath %s) $(RULEDIR)/%s/%s" % (
_component_registrar_service[0],
v,
_component_registrar_service[1],
)] if version_less(v, "2.4.20") else []
)),
),
kt_jvm_library(
Expand Down
3 changes: 3 additions & 0 deletions java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC2.jar
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC2.jar
Git LFS file not shown
2 changes: 1 addition & 1 deletion java/kotlin-extractor/dev/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io
import os

DEFAULT_VERSION = "2.4.10"
DEFAULT_VERSION = "2.4.20-RC2"


def options():
Expand Down
102 changes: 74 additions & 28 deletions java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,9 @@ open class KotlinFileExtractor(
extractMethodAndParameterTypeAccesses: Boolean,
typeSubstitution: TypeSubstitution?,
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
) : Label<out DbCallable> =
forceExtractFunction(
) : Label<out DbCallable> {
val sourceLoc = tw.getLocation(f.parentClassOrNull ?: f)
return forceExtractFunction(
f,
parentId,
extractBody = false,
Expand All @@ -1656,6 +1657,7 @@ open class KotlinFileExtractor(
classTypeArgsIncludingOuterClasses,
overriddenAttributes =
OverriddenFunctionAttributes(
sourceLoc = sourceLoc,
visibility = DescriptorVisibilities.PUBLIC,
modality = Modality.OPEN
)
Expand All @@ -1666,7 +1668,6 @@ open class KotlinFileExtractor(
CompilerGeneratedKinds.INTERFACE_FORWARDER.kind
)
if (extractBody) {
val realFunctionLocId = tw.getLocation(f)
val inheritedDefaultFunction = f.realOverrideTarget
val directlyInheritedSymbol =
when (f) {
Expand All @@ -1686,10 +1687,10 @@ open class KotlinFileExtractor(
(directlyInheritedSymbol.owner.parentClassOrNull ?: return functionId)
.typeWith()

extractExpressionBody(functionId, realFunctionLocId).also { returnId ->
extractExpressionBody(functionId, sourceLoc).also { returnId ->
extractRawMethodAccess(
f,
realFunctionLocId,
sourceLoc,
f.returnType,
functionId,
returnId,
Expand All @@ -1702,7 +1703,7 @@ open class KotlinFileExtractor(
extractVariableAccess(
syntheticParamId,
param.type,
realFunctionLocId,
sourceLoc,
argParentId,
idxOffset + idx,
functionId,
Expand All @@ -1718,14 +1719,15 @@ open class KotlinFileExtractor(
callId,
-1,
returnId,
realFunctionLocId
sourceLoc
)
},
null
)
}
}
}
}

private fun extractFunction(
f: IrFunction,
Expand Down Expand Up @@ -3588,7 +3590,9 @@ open class KotlinFileExtractor(
valueArguments,
enclosingStmt,
enclosingCallable,
idxOffset
idxOffset,
valueParameters = syntacticCallTarget.codeQlValueParameters,
contextArgumentLocation = tw.getWholeFileLocation()
)
},
dispatchReceiver?.type,
Expand Down Expand Up @@ -3802,50 +3806,92 @@ open class KotlinFileExtractor(
enclosingStmt: Label<out DbStmt>,
enclosingCallable: Label<out DbCallable>,
idxOffset: Int
) =
) {
extractCallValueArguments(
callId,
(0 until call.codeQlValueArgumentsCount).map { call.codeQlGetValueArgument(it) },
enclosingStmt,
enclosingCallable,
idxOffset
idxOffset,
valueParameters = call.symbol.owner.codeQlValueParameters,
contextArgumentLocation = tw.getWholeFileLocation()
)
}

private fun extractCallValueArguments(
callId: Label<out DbExprparent>,
valueArguments: List<IrExpression?>,
enclosingStmt: Label<out DbStmt>,
enclosingCallable: Label<out DbCallable>,
idxOffset: Int,
extractVarargAsArray: Boolean = false
extractVarargAsArray: Boolean = false,
valueParameters: List<IrValueParameter>? = null,
contextArgumentLocation: Label<DbLocation>? = null
) {
var i = 0
valueArguments.forEach { arg ->
valueArguments.forEachIndexed { argumentIndex, arg ->
if (arg != null) {
if (arg is IrVararg && !extractVarargAsArray) {
arg.elements.forEachIndexed { varargNo, vararg ->
extractVarargElement(
vararg,
enclosingCallable,
callId,
i + idxOffset + varargNo,
enclosingStmt
)
}
i += arg.elements.size
} else {
extractExpressionExpr(
arg,
enclosingCallable,
val parameter = valueParameters?.getOrNull(argumentIndex)
if (
parameter?.isCodeQlContextParameter() == true &&
arg is IrGetValue &&
contextArgumentLocation != null
) {
extractVariableAccess(
useValueDeclaration(arg.symbol.owner),
arg.type,
contextArgumentLocation,
callId,
(i++) + idxOffset,
i++ + idxOffset,
enclosingCallable,
enclosingStmt
)
} else {
i +=
extractCallValueArgument(
callId,
arg,
enclosingStmt,
enclosingCallable,
i + idxOffset,
extractVarargAsArray
)
}
}
}
}

private fun extractCallValueArgument(
callId: Label<out DbExprparent>,
argument: IrExpression,
enclosingStmt: Label<out DbStmt>,
enclosingCallable: Label<out DbCallable>,
outputIndex: Int,
extractVarargAsArray: Boolean = false
): Int {
if (argument is IrVararg && !extractVarargAsArray) {
argument.elements.forEachIndexed { varargIndex, element ->
extractVarargElement(
element,
enclosingCallable,
callId,
outputIndex + varargIndex,
enclosingStmt
)
}
return argument.elements.size
}

extractExpressionExpr(
argument,
enclosingCallable,
callId,
outputIndex,
enclosingStmt
)
return 1
}

private fun findFunction(cls: IrClass, name: String): IrFunction? =
cls.declarations.findSubType<IrFunction> { it.name.asString() == name }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class MetaAnnotationSupport(
val metaAnnotations = annotationClass.annotations
val jvmRepeatable =
metaAnnotations.find {
it.symbol.owner.parentAsClass.fqNameWhenAvailable ==
JvmAnnotationNames.REPEATABLE_ANNOTATION
it.annotationClass.fqNameWhenAvailable == JvmAnnotationNames.REPEATABLE_ANNOTATION
}
return if (jvmRepeatable != null) {
((jvmRepeatable.codeQlGetValueArgument(0) as? IrClassReference)?.symbol as? IrClassSymbol)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.declarations.IrValueParameter

fun IrValueParameter.isCodeQlContextParameter() = false
Loading