mirror of
https://github.com/github/codeql.git
synced 2026-06-05 21:47:10 +02:00
Compare commits
48 Commits
yoff/pytho
...
andersfugm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b89b6e432a | ||
|
|
9723044342 | ||
|
|
e21bc4da05 | ||
|
|
4a2f244ffa | ||
|
|
ed9e160e89 | ||
|
|
ed996ae48b | ||
|
|
3da195f50f | ||
|
|
0430c71318 | ||
|
|
52f2a5825a | ||
|
|
d55ff83568 | ||
|
|
7edf0100cc | ||
|
|
167c837088 | ||
|
|
af45e53e77 | ||
|
|
d11fc3a00e | ||
|
|
9d5dfea5c5 | ||
|
|
dc0c7d7ec2 | ||
|
|
be9c785cb2 | ||
|
|
1fd31d0ddd | ||
|
|
c4e3720d8a | ||
|
|
0547e9c98d | ||
|
|
3f3bed62d3 | ||
|
|
21f216af8c | ||
|
|
1751d70c62 | ||
|
|
ac8eb50c26 | ||
|
|
1ecdc3614f | ||
|
|
e3b3888bee | ||
|
|
ef9306d82c | ||
|
|
56822f8ee1 | ||
|
|
62207f152c | ||
|
|
d5f94475b5 | ||
|
|
00e95a0757 | ||
|
|
c695c151ea | ||
|
|
5e5a0437e1 | ||
|
|
d95d99848c | ||
|
|
8937e22735 | ||
|
|
37589dd8a0 | ||
|
|
a159dc1c66 | ||
|
|
dc864762c3 | ||
|
|
dd35bc0722 | ||
|
|
043ec857ab | ||
|
|
f5b17b0b48 | ||
|
|
26dca558c7 | ||
|
|
57ce0b3d51 | ||
|
|
408ba2e139 | ||
|
|
7632bdba88 | ||
|
|
4b830c1864 | ||
|
|
d6c8767647 | ||
|
|
ec815397a2 |
@@ -248,6 +248,7 @@ use_repo(
|
||||
"kotlin-compiler-2.2.20-Beta2",
|
||||
"kotlin-compiler-2.3.0",
|
||||
"kotlin-compiler-2.3.20",
|
||||
"kotlin-compiler-2.4.0",
|
||||
"kotlin-compiler-embeddable-1.8.0",
|
||||
"kotlin-compiler-embeddable-1.9.0-Beta",
|
||||
"kotlin-compiler-embeddable-1.9.20-Beta",
|
||||
@@ -259,6 +260,7 @@ use_repo(
|
||||
"kotlin-compiler-embeddable-2.2.20-Beta2",
|
||||
"kotlin-compiler-embeddable-2.3.0",
|
||||
"kotlin-compiler-embeddable-2.3.20",
|
||||
"kotlin-compiler-embeddable-2.4.0",
|
||||
"kotlin-stdlib-1.8.0",
|
||||
"kotlin-stdlib-1.9.0-Beta",
|
||||
"kotlin-stdlib-1.9.20-Beta",
|
||||
@@ -270,6 +272,7 @@ use_repo(
|
||||
"kotlin-stdlib-2.2.20-Beta2",
|
||||
"kotlin-stdlib-2.3.0",
|
||||
"kotlin-stdlib-2.3.20",
|
||||
"kotlin-stdlib-2.4.0",
|
||||
)
|
||||
|
||||
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
Java,"Java 7 to 26 [6]_","javac (OpenJDK and Oracle JDK),
|
||||
|
||||
Eclipse compiler for Java (ECJ) [7]_",``.java``
|
||||
Kotlin,"Kotlin 1.8.0 to 2.3.2\ *x*","kotlinc",``.kt``
|
||||
Kotlin,"Kotlin 1.8.0 to 2.4.\ *x*","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`` [8]_"
|
||||
Python [9]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13",Not applicable,``.py``
|
||||
Ruby [10]_,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"
|
||||
|
||||
@@ -9,9 +9,9 @@ import semmle.go.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
|
||||
import utils.test.InlineFlowTest
|
||||
|
||||
module Config implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node src) { sourceNode(src, "qltest") }
|
||||
predicate isSource(DataFlow::Node source) { sourceNode(source, "qltest") }
|
||||
|
||||
predicate isSink(DataFlow::Node src) { sinkNode(src, "qltest") }
|
||||
predicate isSink(DataFlow::Node sink) { sinkNode(sink, "qltest") }
|
||||
}
|
||||
|
||||
import ValueFlowTest<Config>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
reverseRead
|
||||
| main.go:23:3:23:5 | out | Origin of readStep is missing a PostUpdateNode. |
|
||||
@@ -4,7 +4,7 @@ func source() string {
|
||||
return "untrusted data"
|
||||
}
|
||||
|
||||
func sink(string) {
|
||||
func sink(any) {
|
||||
}
|
||||
|
||||
type A struct {
|
||||
@@ -19,6 +19,10 @@ func functionWithVarArgsParameter(s ...string) string {
|
||||
return s[1]
|
||||
}
|
||||
|
||||
func functionWithVarArgsOutParameter(in string, out ...*string) {
|
||||
*out[0] = in
|
||||
}
|
||||
|
||||
func functionWithSliceOfStructsParameter(s []A) string {
|
||||
return s[1].f
|
||||
}
|
||||
@@ -38,6 +42,12 @@ func main() {
|
||||
sink(functionWithVarArgsParameter(sSlice...)) // $ hasValueFlow="call to functionWithVarArgsParameter"
|
||||
sink(functionWithVarArgsParameter(s0, s1)) // $ hasValueFlow="call to functionWithVarArgsParameter"
|
||||
|
||||
var out1 *string
|
||||
var out2 *string
|
||||
functionWithVarArgsOutParameter(source(), out1, out2)
|
||||
sink(out1) // $ MISSING: hasValueFlow="out1"
|
||||
sink(out2) // $ MISSING: hasValueFlow="out2"
|
||||
|
||||
sliceOfStructs := []A{{f: source()}}
|
||||
sink(sliceOfStructs[0].f) // $ hasValueFlow="selection of f"
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
invalidModelRow
|
||||
testFailures
|
||||
@@ -0,0 +1,21 @@
|
||||
extensions:
|
||||
- addsTo:
|
||||
pack: codeql/go-all
|
||||
extensible: summaryModel
|
||||
data:
|
||||
- ["github.com/nonexistent/test", "", False, "FunctionWithParameter", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
|
||||
- ["github.com/nonexistent/test", "", False, "FunctionWithSliceParameter", "", "", "Argument[0].ArrayElement", "ReturnValue", "value", "manual"]
|
||||
- ["github.com/nonexistent/test", "", False, "FunctionWithVarArgsParameter", "", "", "Argument[0].ArrayElement", "ReturnValue", "value", "manual"]
|
||||
- ["github.com/nonexistent/test", "", False, "FunctionWithVarArgsOutParameter", "", "", "Argument[0]", "Argument[1].ArrayElement", "value", "manual"]
|
||||
- ["github.com/nonexistent/test", "", False, "FunctionWithSliceOfStructsParameter", "", "", "Argument[0].ArrayElement.Field[github.com/nonexistent/test.A.Field]", "ReturnValue", "value", "manual"]
|
||||
- ["github.com/nonexistent/test", "", False, "FunctionWithVarArgsOfStructsParameter", "", "", "Argument[0].ArrayElement.Field[github.com/nonexistent/test.A.Field]", "ReturnValue", "value", "manual"]
|
||||
- addsTo:
|
||||
pack: codeql/go-all
|
||||
extensible: sourceModel
|
||||
data:
|
||||
- ["github.com/nonexistent/test", "", False, "VariadicSource", "", "", "Argument[0]", "qltest", "manual"]
|
||||
- addsTo:
|
||||
pack: codeql/go-all
|
||||
extensible: sinkModel
|
||||
data:
|
||||
- ["github.com/nonexistent/test", "", False, "VariadicSink", "", "", "Argument[0]", "qltest", "manual"]
|
||||
@@ -0,0 +1,22 @@
|
||||
import go
|
||||
import semmle.go.dataflow.ExternalFlow
|
||||
import ModelValidation
|
||||
import utils.test.InlineFlowTest
|
||||
|
||||
module Config implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) {
|
||||
sourceNode(source, "qltest")
|
||||
or
|
||||
exists(Function fn | fn.hasQualifiedName(_, ["source", "taint"]) |
|
||||
source = fn.getACall().getResult()
|
||||
)
|
||||
}
|
||||
|
||||
predicate isSink(DataFlow::Node sink) {
|
||||
sinkNode(sink, "qltest")
|
||||
or
|
||||
exists(Function fn | fn.hasQualifiedName(_, "sink") | sink = fn.getACall().getAnArgument())
|
||||
}
|
||||
}
|
||||
|
||||
import FlowTest<Config, Config>
|
||||
@@ -0,0 +1,5 @@
|
||||
module semmle.go.Packages
|
||||
|
||||
go 1.25
|
||||
|
||||
require github.com/nonexistent/test v0.0.0-20200203000000-0000000000000
|
||||
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/nonexistent/test"
|
||||
)
|
||||
|
||||
func source() string {
|
||||
return "untrusted data"
|
||||
}
|
||||
|
||||
func sink(any) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := source()
|
||||
sink(test.FunctionWithParameter(s)) // $ hasValueFlow="call to FunctionWithParameter"
|
||||
|
||||
stringSlice := []string{source()}
|
||||
sink(stringSlice[0]) // $ hasValueFlow="index expression"
|
||||
|
||||
s0 := ""
|
||||
s1 := source()
|
||||
sSlice := []string{s0, s1}
|
||||
sink(test.FunctionWithParameter(sSlice[1])) // $ hasValueFlow="call to FunctionWithParameter"
|
||||
sink(test.FunctionWithSliceParameter(sSlice)) // $ hasValueFlow="call to FunctionWithSliceParameter"
|
||||
sink(test.FunctionWithVarArgsParameter(sSlice...)) // $ hasValueFlow="call to FunctionWithVarArgsParameter"
|
||||
sink(test.FunctionWithVarArgsParameter(s0, s1)) // $ hasValueFlow="call to FunctionWithVarArgsParameter"
|
||||
|
||||
var out1 *string
|
||||
var out2 *string
|
||||
test.FunctionWithVarArgsOutParameter(source(), out1, out2)
|
||||
sink(out1) // $ MISSING: hasValueFlow="out1"
|
||||
sink(out2) // $ MISSING: hasValueFlow="out2"
|
||||
|
||||
sliceOfStructs := []test.A{{Field: source()}}
|
||||
sink(sliceOfStructs[0].Field) // $ hasValueFlow="selection of Field"
|
||||
|
||||
a0 := test.A{Field: ""}
|
||||
a1 := test.A{Field: source()}
|
||||
aSlice := []test.A{a0, a1}
|
||||
sink(test.FunctionWithSliceOfStructsParameter(aSlice)) // $ hasValueFlow="call to FunctionWithSliceOfStructsParameter"
|
||||
sink(test.FunctionWithVarArgsOfStructsParameter(aSlice...)) // $ hasValueFlow="call to FunctionWithVarArgsOfStructsParameter"
|
||||
sink(test.FunctionWithVarArgsOfStructsParameter(a0, a1)) // $ hasValueFlow="call to FunctionWithVarArgsOfStructsParameter"
|
||||
|
||||
var variadicSource string
|
||||
test.VariadicSource(&variadicSource)
|
||||
sink(variadicSource) // $ MISSING: hasTaintFlow="variadicSource"
|
||||
sink(&variadicSource) // $ MISSING: hasTaintFlow="&..."
|
||||
|
||||
var variadicSourcePtr *string
|
||||
test.VariadicSource(variadicSourcePtr)
|
||||
sink(variadicSourcePtr) // $ MISSING: hasTaintFlow="variadicSourcePtr"
|
||||
sink(*variadicSourcePtr) // $ MISSING: hasTaintFlow="star expression"
|
||||
|
||||
test.VariadicSink(source()) // $ hasTaintFlow="[]type{args}"
|
||||
}
|
||||
32
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/vendor/github.com/nonexistent/test/stub.go
generated
vendored
Normal file
32
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/vendor/github.com/nonexistent/test/stub.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package test
|
||||
|
||||
type A struct {
|
||||
Field string
|
||||
}
|
||||
|
||||
func FunctionWithParameter(s string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func FunctionWithSliceParameter(s []string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func FunctionWithVarArgsParameter(s ...string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func FunctionWithVarArgsOutParameter(in string, out ...*string) {
|
||||
}
|
||||
|
||||
func FunctionWithSliceOfStructsParameter(s []A) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func FunctionWithVarArgsOfStructsParameter(s ...A) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func VariadicSource(s ...*string) {}
|
||||
|
||||
func VariadicSink(s ...string) {}
|
||||
3
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/vendor/modules.txt
vendored
Normal file
3
go/ql/test/library-tests/semmle/go/dataflow/VarArgsWithExternalFlow/vendor/modules.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# github.com/nonexistent/test v0.0.0-20200203000000-0000000000000
|
||||
## explicit
|
||||
github.com/nonexistent/test
|
||||
@@ -20,6 +20,9 @@ class SummaryModelTest extends DataFlow::FunctionModel {
|
||||
this.hasQualifiedName("github.com/nonexistent/test", "FunctionWithVarArgsParameter") and
|
||||
(inp.isParameter(_) and outp.isResult())
|
||||
or
|
||||
this.hasQualifiedName("github.com/nonexistent/test", "FunctionWithVarArgsOutParameter") and
|
||||
(inp.isParameter(0) and outp.isParameter(any(int i | i >= 1)))
|
||||
or
|
||||
this.hasQualifiedName("github.com/nonexistent/test", "FunctionWithSliceOfStructsParameter") and
|
||||
(inp.isParameter(0) and outp.isResult())
|
||||
or
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module semmle.go.Packages
|
||||
|
||||
go 1.17
|
||||
go 1.25
|
||||
|
||||
require github.com/nonexistent/test v0.0.0-20200203000000-0000000000000
|
||||
|
||||
@@ -8,7 +8,7 @@ func source() string {
|
||||
return "untrusted data"
|
||||
}
|
||||
|
||||
func sink(string) {
|
||||
func sink(any) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -21,10 +21,17 @@ func main() {
|
||||
s0 := ""
|
||||
s1 := source()
|
||||
sSlice := []string{s0, s1}
|
||||
sink(test.FunctionWithParameter(sSlice[1])) // $ hasValueFlow="call to FunctionWithParameter"
|
||||
sink(test.FunctionWithSliceParameter(sSlice)) // $ hasTaintFlow="call to FunctionWithSliceParameter" MISSING: hasValueFlow="call to FunctionWithSliceParameter"
|
||||
sink(test.FunctionWithVarArgsParameter(sSlice...)) // $ hasTaintFlow="call to FunctionWithVarArgsParameter" MISSING: hasValueFlow="call to FunctionWithVarArgsParameter"
|
||||
sink(test.FunctionWithVarArgsParameter(s0, s1)) // $ MISSING: hasValueFlow="call to FunctionWithVarArgsParameter"
|
||||
sink(test.FunctionWithParameter(sSlice[1])) // $ hasValueFlow="call to FunctionWithParameter"
|
||||
sink(test.FunctionWithSliceParameter(sSlice)) // $ hasTaintFlow="call to FunctionWithSliceParameter" MISSING: hasValueFlow="call to FunctionWithSliceParameter"
|
||||
sink(test.FunctionWithVarArgsParameter(sSlice...)) // $ hasTaintFlow="call to FunctionWithVarArgsParameter" MISSING: hasValueFlow="call to FunctionWithVarArgsParameter"
|
||||
randomFunctionWithMoreThanOneParameter(1, 2, 3, 4, 5) // This is needed to make the next line pass, because we need to have seen a call to a function with at least 2 parameters for ParameterInput to exist with index 1.
|
||||
sink(test.FunctionWithVarArgsParameter(s0, s1)) // $ hasValueFlow="call to FunctionWithVarArgsParameter"
|
||||
|
||||
var out1 *string
|
||||
var out2 *string
|
||||
test.FunctionWithVarArgsOutParameter(source(), out1, out2)
|
||||
sink(out1) // $ hasValueFlow="out1"
|
||||
sink(out2) // $ hasValueFlow="out2"
|
||||
|
||||
sliceOfStructs := []test.A{{Field: source()}}
|
||||
sink(sliceOfStructs[0].Field) // $ hasValueFlow="selection of Field"
|
||||
@@ -37,3 +44,6 @@ func main() {
|
||||
sink(test.FunctionWithVarArgsOfStructsParameter(aSlice...)) // $ MISSING: hasValueFlow="call to FunctionWithVarArgsOfStructsParameter"
|
||||
sink(test.FunctionWithVarArgsOfStructsParameter(a0, a1)) // $ MISSING: hasValueFlow="call to FunctionWithVarArgsOfStructsParameter"
|
||||
}
|
||||
|
||||
func randomFunctionWithMoreThanOneParameter(i1, i2, i3, i4, i5 int) {
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -16,6 +16,9 @@ func FunctionWithVarArgsParameter(s ...string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func FunctionWithVarArgsOutParameter(in string, out ...*string) {
|
||||
}
|
||||
|
||||
func FunctionWithSliceOfStructsParameter(s []A) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -64,8 +64,14 @@ _resources = [
|
||||
r[len("src/main/resources/"):],
|
||||
)
|
||||
for r in glob(["src/main/resources/**"])
|
||||
if r != "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
|
||||
]
|
||||
|
||||
_compiler_plugin_registrar_service = (
|
||||
"src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar",
|
||||
"META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar",
|
||||
)
|
||||
|
||||
kt_javac_options(
|
||||
name = "javac-options",
|
||||
release = "8",
|
||||
@@ -91,19 +97,26 @@ kt_javac_options(
|
||||
# * `resource_strip_prefix` is unique per jar, so we must also put other resources under the same version prefix
|
||||
genrule(
|
||||
name = "resources-%s" % v,
|
||||
srcs = [src for src, _ in _resources],
|
||||
srcs = [src for src, _ in _resources] + (
|
||||
[_compiler_plugin_registrar_service[0]] if not version_less(v, "2.4.0") else []
|
||||
),
|
||||
outs = [
|
||||
"%s/com/github/codeql/extractor.name" % v,
|
||||
] + [
|
||||
"%s/%s" % (v, target)
|
||||
for _, target in _resources
|
||||
],
|
||||
] + (
|
||||
["%s/%s" % (v, _compiler_plugin_registrar_service[1])] if not version_less(v, "2.4.0") else []
|
||||
),
|
||||
cmd = "\n".join([
|
||||
"echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v),
|
||||
] + [
|
||||
"cp $(execpath %s) $(RULEDIR)/%s/%s" % (source, v, target)
|
||||
for source, target in _resources
|
||||
]),
|
||||
] + (
|
||||
["cp $(execpath %s) $(RULEDIR)/%s/%s" % (_compiler_plugin_registrar_service[0], v, _compiler_plugin_registrar_service[1])]
|
||||
if not version_less(v, "2.4.0") else []
|
||||
)),
|
||||
),
|
||||
kt_jvm_library(
|
||||
name = "%s-%s" % (_extractor_name_prefix, v),
|
||||
|
||||
BIN
java/kotlin-extractor/deps/kotlin-compiler-2.4.0.jar
(Stored with Git LFS)
Normal file
BIN
java/kotlin-extractor/deps/kotlin-compiler-2.4.0.jar
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.0.jar
(Stored with Git LFS)
Normal file
BIN
java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.0.jar
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
java/kotlin-extractor/deps/kotlin-stdlib-2.4.0.jar
(Stored with Git LFS)
Normal file
BIN
java/kotlin-extractor/deps/kotlin-stdlib-2.4.0.jar
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -27,7 +27,7 @@ import shutil
|
||||
import io
|
||||
import os
|
||||
|
||||
DEFAULT_VERSION = "2.3.20"
|
||||
DEFAULT_VERSION = "2.4.0"
|
||||
|
||||
|
||||
def options():
|
||||
|
||||
@@ -3,32 +3,21 @@
|
||||
|
||||
package com.github.codeql
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.extensions.LoadingOrder
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
|
||||
class KotlinExtractorComponentRegistrar : Kotlin2ComponentRegistrar() {
|
||||
override fun registerProjectComponents(
|
||||
project: MockProject,
|
||||
configuration: CompilerConfiguration
|
||||
) {
|
||||
override fun doRegisterExtensions(configuration: CompilerConfiguration) {
|
||||
val invocationTrapFile = configuration[KEY_INVOCATION_TRAP_FILE]
|
||||
if (invocationTrapFile == null) {
|
||||
throw Exception("Required argument for TRAP invocation file not given")
|
||||
}
|
||||
// Register with LoadingOrder.LAST to ensure the extractor runs after other
|
||||
// IR generation plugins (like kotlinx.serialization) have generated their code.
|
||||
val extensionPoint = project.extensionArea.getExtensionPoint(IrGenerationExtension.extensionPointName)
|
||||
extensionPoint.registerExtension(
|
||||
registerExtractorExtension(
|
||||
KotlinExtractorExtension(
|
||||
invocationTrapFile,
|
||||
configuration[KEY_CHECK_TRAP_IDENTICAL] ?: false,
|
||||
configuration[KEY_COMPILATION_STARTTIME],
|
||||
configuration[KEY_EXIT_AFTER_EXTRACTION] ?: false
|
||||
),
|
||||
LoadingOrder.LAST,
|
||||
project
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,9 +173,9 @@ open class KotlinFileExtractor(
|
||||
when (d) {
|
||||
is IrFunction ->
|
||||
when (d.name.asString()) {
|
||||
"toString" -> d.valueParameters.isEmpty()
|
||||
"hashCode" -> d.valueParameters.isEmpty()
|
||||
"equals" -> d.valueParameters.singleOrNull()?.type?.isNullableAny() ?: false
|
||||
"toString" -> d.codeQlValueParameters.isEmpty()
|
||||
"hashCode" -> d.codeQlValueParameters.isEmpty()
|
||||
"equals" -> d.codeQlValueParameters.singleOrNull()?.type?.isNullableAny() ?: false
|
||||
else -> false
|
||||
} && isJavaBinaryDeclaration(d)
|
||||
else -> false
|
||||
@@ -721,7 +721,7 @@ open class KotlinFileExtractor(
|
||||
(it.type as? IrSimpleType)?.classFqName?.asString() != "kotlin.Deprecated"
|
||||
} +
|
||||
// Note we lose any arguments to @java.lang.Deprecated that were written in source.
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
jldConstructor.returnType,
|
||||
@@ -781,13 +781,13 @@ open class KotlinFileExtractor(
|
||||
val locId = tw.getLocation(constructorCall)
|
||||
tw.writeHasLocation(id, locId)
|
||||
|
||||
for (i in 0 until constructorCall.valueArgumentsCount) {
|
||||
val param = constructorCall.symbol.owner.valueParameters[i]
|
||||
for (i in 0 until constructorCall.codeQlValueArgumentsCount) {
|
||||
val param = constructorCall.symbol.owner.codeQlValueParameters[i]
|
||||
val prop =
|
||||
constructorCall.symbol.owner.parentAsClass.declarations
|
||||
.filterIsInstance<IrProperty>()
|
||||
.first { it.name == param.name }
|
||||
val v = constructorCall.getValueArgument(i) ?: param.defaultValue?.expression
|
||||
val v = constructorCall.codeQlGetValueArgument(i) ?: param.defaultValue?.expression
|
||||
val getter = prop.getter
|
||||
if (getter == null) {
|
||||
logger.warnElement("Expected annotation property to define a getter", prop)
|
||||
@@ -1115,9 +1115,9 @@ open class KotlinFileExtractor(
|
||||
returnId,
|
||||
0,
|
||||
returnId,
|
||||
f.valueParameters.size,
|
||||
f.codeQlValueParameters.size,
|
||||
{ argParent, idxOffset ->
|
||||
f.valueParameters.forEachIndexed { idx, param ->
|
||||
f.codeQlValueParameters.forEachIndexed { idx, param ->
|
||||
val syntheticParamId = useValueParameter(param, proxyFunctionId)
|
||||
extractVariableAccess(
|
||||
syntheticParamId,
|
||||
@@ -1695,9 +1695,9 @@ open class KotlinFileExtractor(
|
||||
returnId,
|
||||
0,
|
||||
returnId,
|
||||
f.valueParameters.size,
|
||||
f.codeQlValueParameters.size,
|
||||
{ argParentId, idxOffset ->
|
||||
f.valueParameters.mapIndexed { idx, param ->
|
||||
f.codeQlValueParameters.mapIndexed { idx, param ->
|
||||
val syntheticParamId = useValueParameter(param, functionId)
|
||||
extractVariableAccess(
|
||||
syntheticParamId,
|
||||
@@ -1792,7 +1792,7 @@ open class KotlinFileExtractor(
|
||||
extractBody: Boolean,
|
||||
extractMethodAndParameterTypeAccesses: Boolean
|
||||
) {
|
||||
if (f.valueParameters.none { it.defaultValue != null }) return
|
||||
if (f.codeQlValueParameters.none { it.defaultValue != null }) return
|
||||
|
||||
val id = getDefaultsMethodLabel(f)
|
||||
if (id == null) {
|
||||
@@ -1800,7 +1800,7 @@ open class KotlinFileExtractor(
|
||||
return
|
||||
}
|
||||
val locId = getLocation(f, null)
|
||||
val extReceiver = f.extensionReceiverParameter
|
||||
val extReceiver = f.codeQlExtensionReceiverParameter
|
||||
val dispatchReceiver = if (f.shouldExtractAsStatic) null else f.dispatchReceiverParameter
|
||||
val parameterTypes = getDefaultsMethodArgTypes(f)
|
||||
val allParamTypeResults =
|
||||
@@ -1869,7 +1869,7 @@ open class KotlinFileExtractor(
|
||||
tw.writeCompiler_generated(id, CompilerGeneratedKinds.DEFAULT_ARGUMENTS_METHOD.kind)
|
||||
|
||||
if (extractBody) {
|
||||
val nonSyntheticParams = listOfNotNull(dispatchReceiver) + f.valueParameters
|
||||
val nonSyntheticParams = listOfNotNull(dispatchReceiver) + f.codeQlValueParameters
|
||||
// This stack entry represents as if we're extracting the 'real' function `f`, giving
|
||||
// the indices of its non-synthetic parameters
|
||||
// such that when we extract the default expressions below, any reference to f's nth
|
||||
@@ -1895,12 +1895,12 @@ open class KotlinFileExtractor(
|
||||
val realParamsVarId = getValueParameterLabel(id, parameterTypes.size - 2)
|
||||
val intType = pluginContext.irBuiltIns.intType
|
||||
val paramIdxOffset =
|
||||
listOf(dispatchReceiver, f.extensionReceiverParameter).count { it != null }
|
||||
listOf(dispatchReceiver, f.codeQlExtensionReceiverParameter).count { it != null }
|
||||
extractBlockBody(id, locId).also { blockId ->
|
||||
var nextStmt = 0
|
||||
// For each parameter with a default, sub in the default value if the caller
|
||||
// hasn't supplied a value:
|
||||
f.valueParameters.forEachIndexed { paramIdx, param ->
|
||||
f.codeQlValueParameters.forEachIndexed { paramIdx, param ->
|
||||
val defaultVal = param.defaultValue
|
||||
if (defaultVal != null) {
|
||||
extractIfStmt(locId, blockId, nextStmt++, id).also { ifId ->
|
||||
@@ -1975,7 +1975,7 @@ open class KotlinFileExtractor(
|
||||
id
|
||||
)
|
||||
tw.writeHasLocation(thisCallId, locId)
|
||||
f.valueParameters.forEachIndexed { idx, param ->
|
||||
f.codeQlValueParameters.forEachIndexed { idx, param ->
|
||||
extractVariableAccess(
|
||||
tw.getLabelFor<DbParam>(getValueParameterLabel(id, idx)),
|
||||
param.type,
|
||||
@@ -2003,9 +2003,9 @@ open class KotlinFileExtractor(
|
||||
)
|
||||
.also { thisCallId ->
|
||||
val realFnIdxOffset =
|
||||
if (f.extensionReceiverParameter != null) 1 else 0
|
||||
if (f.codeQlExtensionReceiverParameter != null) 1 else 0
|
||||
val paramMappings =
|
||||
f.valueParameters.mapIndexed { idx, param ->
|
||||
f.codeQlValueParameters.mapIndexed { idx, param ->
|
||||
Triple(
|
||||
param.type,
|
||||
idx + paramIdxOffset,
|
||||
@@ -2156,7 +2156,7 @@ open class KotlinFileExtractor(
|
||||
val dispatchReceiver =
|
||||
f.dispatchReceiverParameter?.let { IrGetValueImpl(-1, -1, it.symbol) }
|
||||
val extensionReceiver =
|
||||
f.extensionReceiverParameter?.let { IrGetValueImpl(-1, -1, it.symbol) }
|
||||
f.codeQlExtensionReceiverParameter?.let { IrGetValueImpl(-1, -1, it.symbol) }
|
||||
|
||||
extractExpressionBody(overloadId, realFunctionLocId).also { returnId ->
|
||||
extractsDefaultsCall(
|
||||
@@ -2180,28 +2180,28 @@ open class KotlinFileExtractor(
|
||||
if (!f.hasAnnotation(jvmOverloadsFqName)) {
|
||||
if (
|
||||
f is IrConstructor &&
|
||||
f.valueParameters.isNotEmpty() &&
|
||||
f.valueParameters.all { it.defaultValue != null } &&
|
||||
f.codeQlValueParameters.isNotEmpty() &&
|
||||
f.codeQlValueParameters.all { it.defaultValue != null } &&
|
||||
f.parentClassOrNull?.let {
|
||||
// Don't create a default constructor for an annotation class, or a class
|
||||
// that explicitly declares a no-arg constructor.
|
||||
!it.isAnnotationClass &&
|
||||
it.declarations.none { d ->
|
||||
d is IrConstructor && d.valueParameters.isEmpty()
|
||||
d is IrConstructor && d.codeQlValueParameters.isEmpty()
|
||||
}
|
||||
} == true
|
||||
) {
|
||||
// Per https://kotlinlang.org/docs/classes.html#creating-instances-of-classes, a
|
||||
// single default overload gets created specifically
|
||||
// when we have all default parameters, regardless of `@JvmOverloads`.
|
||||
extractGeneratedOverload(f.valueParameters.map { _ -> null })
|
||||
extractGeneratedOverload(f.codeQlValueParameters.map { _ -> null })
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
val paramList: MutableList<IrValueParameter?> = f.valueParameters.toMutableList()
|
||||
for (n in (f.valueParameters.size - 1) downTo 0) {
|
||||
if (f.valueParameters[n].defaultValue != null) {
|
||||
val paramList: MutableList<IrValueParameter?> = f.codeQlValueParameters.toMutableList()
|
||||
for (n in (f.codeQlValueParameters.size - 1) downTo 0) {
|
||||
if (f.codeQlValueParameters[n].defaultValue != null) {
|
||||
paramList[n] = null // Remove this parameter, to be replaced by a default value
|
||||
extractGeneratedOverload(paramList)
|
||||
}
|
||||
@@ -2327,7 +2327,7 @@ open class KotlinFileExtractor(
|
||||
getClassByFqName(pluginContext, it)?.let { annotationClass ->
|
||||
annotationClass.owner.declarations.firstIsInstanceOrNull<IrConstructor>()?.let {
|
||||
annotationConstructor ->
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
annotationConstructor.returnType,
|
||||
@@ -2388,13 +2388,13 @@ open class KotlinFileExtractor(
|
||||
id
|
||||
}
|
||||
|
||||
val extReceiver = f.extensionReceiverParameter
|
||||
val extReceiver = f.codeQlExtensionReceiverParameter
|
||||
// The following parameter order is correct, because member $default methods (where
|
||||
// the order would be [dispatchParam], [extensionParam], normalParams) are not
|
||||
// extracted here
|
||||
val fParameters =
|
||||
listOfNotNull(extReceiver) +
|
||||
(overriddenAttributes?.valueParameters ?: f.valueParameters)
|
||||
(overriddenAttributes?.valueParameters ?: f.codeQlValueParameters)
|
||||
val paramTypes =
|
||||
fParameters.mapIndexed { i, vp ->
|
||||
extractValueParameter(
|
||||
@@ -3069,14 +3069,14 @@ open class KotlinFileExtractor(
|
||||
logger.errorElement("Unexpected dispatch receiver found", c)
|
||||
}
|
||||
|
||||
if (c.valueArgumentsCount < 1) {
|
||||
if (c.codeQlValueArgumentsCount < 1) {
|
||||
logger.errorElement("No arguments found", c)
|
||||
return
|
||||
}
|
||||
|
||||
extractArgument(id, c, callable, enclosingStmt, 0, "Operand null")
|
||||
|
||||
if (c.valueArgumentsCount > 1) {
|
||||
if (c.codeQlValueArgumentsCount > 1) {
|
||||
logger.errorElement("Extra arguments found", c)
|
||||
}
|
||||
}
|
||||
@@ -3095,21 +3095,21 @@ open class KotlinFileExtractor(
|
||||
logger.errorElement("Unexpected dispatch receiver found", c)
|
||||
}
|
||||
|
||||
if (c.valueArgumentsCount < 1) {
|
||||
if (c.codeQlValueArgumentsCount < 1) {
|
||||
logger.errorElement("No arguments found", c)
|
||||
return
|
||||
}
|
||||
|
||||
extractArgument(id, c, callable, enclosingStmt, 0, "LHS null")
|
||||
|
||||
if (c.valueArgumentsCount < 2) {
|
||||
if (c.codeQlValueArgumentsCount < 2) {
|
||||
logger.errorElement("No RHS found", c)
|
||||
return
|
||||
}
|
||||
|
||||
extractArgument(id, c, callable, enclosingStmt, 1, "RHS null")
|
||||
|
||||
if (c.valueArgumentsCount > 2) {
|
||||
if (c.codeQlValueArgumentsCount > 2) {
|
||||
logger.errorElement("Extra arguments found", c)
|
||||
}
|
||||
}
|
||||
@@ -3122,7 +3122,7 @@ open class KotlinFileExtractor(
|
||||
idx: Int,
|
||||
msg: String
|
||||
) {
|
||||
val op = c.getValueArgument(idx)
|
||||
val op = c.codeQlGetValueArgument(idx)
|
||||
if (op == null) {
|
||||
logger.errorElement(msg, c)
|
||||
} else {
|
||||
@@ -3267,8 +3267,8 @@ open class KotlinFileExtractor(
|
||||
// and which should be replaced by defaults. The final Object parameter is apparently always
|
||||
// null.
|
||||
(listOfNotNull(if (f.shouldExtractAsStatic) null else f.dispatchReceiverParameter?.type) +
|
||||
listOfNotNull(f.extensionReceiverParameter?.type) +
|
||||
f.valueParameters.map { it.type } +
|
||||
listOfNotNull(f.codeQlExtensionReceiverParameter?.type) +
|
||||
f.codeQlValueParameters.map { it.type } +
|
||||
listOf(pluginContext.irBuiltIns.intType, getDefaultsMethodLastArgType(f)))
|
||||
.map { erase(it) }
|
||||
|
||||
@@ -3345,7 +3345,7 @@ open class KotlinFileExtractor(
|
||||
val overriddenCallTarget =
|
||||
(callTarget as? IrSimpleFunction)?.allOverridden(includeSelf = true)?.firstOrNull {
|
||||
it.overriddenSymbols.isEmpty() &&
|
||||
it.valueParameters.any { p -> p.defaultValue != null }
|
||||
it.codeQlValueParameters.any { p -> p.defaultValue != null }
|
||||
} ?: callTarget
|
||||
if (isExternalDeclaration(overriddenCallTarget)) {
|
||||
// Likewise, ensure the overridden target gets extracted.
|
||||
@@ -3419,7 +3419,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
val valueArgsWithDummies =
|
||||
valueArguments.zip(callTarget.valueParameters).map { (expr, param) ->
|
||||
valueArguments.zip(callTarget.codeQlValueParameters).map { (expr, param) ->
|
||||
expr ?: IrConstImpl.defaultValueForType(0, 0, param.type)
|
||||
}
|
||||
|
||||
@@ -3529,7 +3529,7 @@ open class KotlinFileExtractor(
|
||||
callTarget: IrFunction,
|
||||
valueArguments: List<IrExpression?>
|
||||
): Boolean {
|
||||
val varargParam = callTarget.valueParameters.withIndex().find { it.value.isVararg }
|
||||
val varargParam = callTarget.codeQlValueParameters.withIndex().find { it.value.isVararg }
|
||||
// If the vararg param is the only one not specified, and it has no default value, then we
|
||||
// don't need to call a $default method,
|
||||
// as omitting it already implies passing an empty vararg array.
|
||||
@@ -3805,7 +3805,7 @@ open class KotlinFileExtractor(
|
||||
) =
|
||||
extractCallValueArguments(
|
||||
callId,
|
||||
(0 until call.valueArgumentsCount).map { call.getValueArgument(it) },
|
||||
(0 until call.codeQlValueArgumentsCount).map { call.codeQlGetValueArgument(it) },
|
||||
enclosingStmt,
|
||||
enclosingCallable,
|
||||
idxOffset
|
||||
@@ -3874,7 +3874,7 @@ open class KotlinFileExtractor(
|
||||
(owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type ||
|
||||
(owner.parent is IrExternalPackageFragment &&
|
||||
getFileClassFqName(owner)?.asString() == type)) &&
|
||||
owner.valueParameters
|
||||
owner.codeQlValueParameters
|
||||
.map { it.type.classFqName?.asString() }
|
||||
.toTypedArray() contentEquals parameterTypes
|
||||
}
|
||||
@@ -3926,8 +3926,8 @@ open class KotlinFileExtractor(
|
||||
val result =
|
||||
javaLangString?.declarations?.findSubType<IrFunction> {
|
||||
it.name.asString() == "valueOf" &&
|
||||
it.valueParameters.size == 1 &&
|
||||
it.valueParameters[0].type == pluginContext.irBuiltIns.anyNType
|
||||
it.codeQlValueParameters.size == 1 &&
|
||||
it.codeQlValueParameters[0].type == pluginContext.irBuiltIns.anyNType
|
||||
}
|
||||
if (result == null) {
|
||||
logger.error("Couldn't find declaration java.lang.String.valueOf(Object)")
|
||||
@@ -3951,7 +3951,7 @@ open class KotlinFileExtractor(
|
||||
val kotlinNoWhenBranchMatchedConstructor by lazy {
|
||||
val result =
|
||||
kotlinNoWhenBranchMatchedExn?.declarations?.findSubType<IrConstructor> {
|
||||
it.valueParameters.isEmpty()
|
||||
it.codeQlValueParameters.isEmpty()
|
||||
}
|
||||
if (result == null) {
|
||||
logger.error("Couldn't find no-arg constructor for kotlin.NoWhenBranchMatchedException")
|
||||
@@ -3990,7 +3990,7 @@ open class KotlinFileExtractor(
|
||||
verboseln("No match as function name is ${target.name.asString()} not $fName")
|
||||
return false
|
||||
}
|
||||
val extensionReceiverParameter = target.extensionReceiverParameter
|
||||
val extensionReceiverParameter = target.codeQlExtensionReceiverParameter
|
||||
val targetClass =
|
||||
if (extensionReceiverParameter == null) {
|
||||
if (isNullable == true) {
|
||||
@@ -4098,8 +4098,8 @@ open class KotlinFileExtractor(
|
||||
) {
|
||||
val typeArgs =
|
||||
if (extractMethodTypeArguments)
|
||||
(0 until c.typeArgumentsCount)
|
||||
.map { c.getTypeArgument(it) }
|
||||
(0 until c.codeQlTypeArgumentsCount)
|
||||
.map { c.codeQlGetTypeArgument(it) }
|
||||
.requireNoNullsOrNull()
|
||||
else listOf()
|
||||
|
||||
@@ -4116,9 +4116,9 @@ open class KotlinFileExtractor(
|
||||
parent,
|
||||
idx,
|
||||
enclosingStmt,
|
||||
(0 until c.valueArgumentsCount).map { c.getValueArgument(it) },
|
||||
(0 until c.codeQlValueArgumentsCount).map { c.codeQlGetValueArgument(it) },
|
||||
c.dispatchReceiver,
|
||||
c.extensionReceiver,
|
||||
c.codeQlExtensionReceiver,
|
||||
typeArgs,
|
||||
extractClassTypeArguments,
|
||||
c.superQualifierSymbol
|
||||
@@ -4126,12 +4126,12 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
fun extractSpecialEnumFunction(fnName: String) {
|
||||
if (c.typeArgumentsCount != 1) {
|
||||
if (c.codeQlTypeArgumentsCount != 1) {
|
||||
logger.errorElement("Expected to find exactly one type argument", c)
|
||||
return
|
||||
}
|
||||
|
||||
val enumType = (c.getTypeArgument(0) as? IrSimpleType)?.classifier?.owner
|
||||
val enumType = (c.codeQlGetTypeArgument(0) as? IrSimpleType)?.classifier?.owner
|
||||
if (enumType == null) {
|
||||
logger.errorElement("Couldn't find type of enum type", c)
|
||||
return
|
||||
@@ -4178,13 +4178,13 @@ open class KotlinFileExtractor(
|
||||
} else {
|
||||
extractExpressionExpr(receiver, callable, id, 0, enclosingStmt)
|
||||
}
|
||||
if (c.valueArgumentsCount < 1) {
|
||||
if (c.codeQlValueArgumentsCount < 1) {
|
||||
logger.errorElement("No RHS found", c)
|
||||
} else {
|
||||
if (c.valueArgumentsCount > 1) {
|
||||
if (c.codeQlValueArgumentsCount > 1) {
|
||||
logger.errorElement("Extra arguments found", c)
|
||||
}
|
||||
val arg = c.getValueArgument(0)
|
||||
val arg = c.codeQlGetValueArgument(0)
|
||||
if (arg == null) {
|
||||
logger.errorElement("RHS null", c)
|
||||
} else {
|
||||
@@ -4205,7 +4205,7 @@ open class KotlinFileExtractor(
|
||||
} else {
|
||||
extractExpressionExpr(receiver, callable, id, 0, enclosingStmt)
|
||||
}
|
||||
if (c.valueArgumentsCount > 0) {
|
||||
if (c.codeQlValueArgumentsCount > 0) {
|
||||
logger.errorElement("Extra arguments found", c)
|
||||
}
|
||||
}
|
||||
@@ -4219,7 +4219,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
fun binopExt(id: Label<out DbExpr>) {
|
||||
binopReceiver(id, c.extensionReceiver, "Extension receiver")
|
||||
binopReceiver(id, c.codeQlExtensionReceiver, "Extension receiver")
|
||||
}
|
||||
|
||||
fun unaryopDisp(id: Label<out DbExpr>) {
|
||||
@@ -4227,7 +4227,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
fun unaryopExt(id: Label<out DbExpr>) {
|
||||
unaryopReceiver(id, c.extensionReceiver, "Extension receiver")
|
||||
unaryopReceiver(id, c.codeQlExtensionReceiver, "Extension receiver")
|
||||
}
|
||||
|
||||
val dr = c.dispatchReceiver
|
||||
@@ -4249,7 +4249,7 @@ open class KotlinFileExtractor(
|
||||
parent,
|
||||
idx,
|
||||
enclosingStmt,
|
||||
listOf(c.extensionReceiver, c.getValueArgument(0)),
|
||||
listOf(c.codeQlExtensionReceiver, c.codeQlGetValueArgument(0)),
|
||||
null,
|
||||
null
|
||||
)
|
||||
@@ -4350,7 +4350,7 @@ open class KotlinFileExtractor(
|
||||
// != gets desugared into not and ==. Here we resugar it.
|
||||
c.origin == IrStatementOrigin.EXCLEQ &&
|
||||
isFunction(target, "kotlin", "Boolean", "not") &&
|
||||
c.valueArgumentsCount == 0 &&
|
||||
c.codeQlValueArgumentsCount == 0 &&
|
||||
dr != null &&
|
||||
dr is IrCall &&
|
||||
isBuiltinCallInternal(dr, "EQEQ") -> {
|
||||
@@ -4362,7 +4362,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
c.origin == IrStatementOrigin.EXCLEQEQ &&
|
||||
isFunction(target, "kotlin", "Boolean", "not") &&
|
||||
c.valueArgumentsCount == 0 &&
|
||||
c.codeQlValueArgumentsCount == 0 &&
|
||||
dr != null &&
|
||||
dr is IrCall &&
|
||||
isBuiltinCallInternal(dr, "EQEQEQ") -> {
|
||||
@@ -4374,7 +4374,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
c.origin == IrStatementOrigin.EXCLEQ &&
|
||||
isFunction(target, "kotlin", "Boolean", "not") &&
|
||||
c.valueArgumentsCount == 0 &&
|
||||
c.codeQlValueArgumentsCount == 0 &&
|
||||
dr != null &&
|
||||
dr is IrCall &&
|
||||
isBuiltinCallInternal(dr, "ieee754equals") -> {
|
||||
@@ -4576,7 +4576,7 @@ open class KotlinFileExtractor(
|
||||
parent,
|
||||
idx,
|
||||
enclosingStmt,
|
||||
listOf(c.extensionReceiver),
|
||||
listOf(c.codeQlExtensionReceiver),
|
||||
null,
|
||||
null
|
||||
)
|
||||
@@ -4596,8 +4596,8 @@ open class KotlinFileExtractor(
|
||||
val locId = tw.getLocation(c)
|
||||
extractExprContext(id, locId, callable, enclosingStmt)
|
||||
|
||||
if (c.typeArgumentsCount == 1) {
|
||||
val typeArgument = c.getTypeArgument(0)
|
||||
if (c.codeQlTypeArgumentsCount == 1) {
|
||||
val typeArgument = c.codeQlGetTypeArgument(0)
|
||||
if (typeArgument == null) {
|
||||
logger.errorElement("Type argument missing in an arrayOfNulls call", c)
|
||||
} else {
|
||||
@@ -4618,8 +4618,8 @@ open class KotlinFileExtractor(
|
||||
)
|
||||
}
|
||||
|
||||
if (c.valueArgumentsCount == 1) {
|
||||
val dim = c.getValueArgument(0)
|
||||
if (c.codeQlValueArgumentsCount == 1) {
|
||||
val dim = c.codeQlGetValueArgument(0)
|
||||
if (dim != null) {
|
||||
extractExpressionExpr(dim, callable, id, 0, enclosingStmt)
|
||||
} else {
|
||||
@@ -4651,8 +4651,8 @@ open class KotlinFileExtractor(
|
||||
c.type.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
|
||||
} else {
|
||||
// TODO: is there any reason not to always use getArrayElementTypeCodeQL?
|
||||
if (c.typeArgumentsCount == 1) {
|
||||
c.getTypeArgument(0).also {
|
||||
if (c.codeQlTypeArgumentsCount == 1) {
|
||||
c.codeQlGetTypeArgument(0).also {
|
||||
if (it == null) {
|
||||
logger.errorElement(
|
||||
"Type argument missing in an arrayOf call",
|
||||
@@ -4670,7 +4670,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
val arg =
|
||||
if (c.valueArgumentsCount == 1) c.getValueArgument(0)
|
||||
if (c.codeQlValueArgumentsCount == 1) c.codeQlGetValueArgument(0)
|
||||
else {
|
||||
logger.errorElement(
|
||||
"Expected to find only one (vararg) argument in ${c.symbol.owner.name.asString()} call",
|
||||
@@ -4719,7 +4719,7 @@ open class KotlinFileExtractor(
|
||||
return
|
||||
}
|
||||
|
||||
val ext = c.extensionReceiver
|
||||
val ext = c.codeQlExtensionReceiver
|
||||
if (ext == null) {
|
||||
logger.errorElement(
|
||||
"No extension receiver found for `KClass::java` call",
|
||||
@@ -4826,8 +4826,8 @@ open class KotlinFileExtractor(
|
||||
c.origin == IrStatementOrigin.EQ &&
|
||||
c.dispatchReceiver != null -> {
|
||||
val array = c.dispatchReceiver
|
||||
val arrayIdx = c.getValueArgument(0)
|
||||
val assignedValue = c.getValueArgument(1)
|
||||
val arrayIdx = c.codeQlGetValueArgument(0)
|
||||
val assignedValue = c.codeQlGetValueArgument(1)
|
||||
|
||||
if (array != null && arrayIdx != null && assignedValue != null) {
|
||||
|
||||
@@ -4882,22 +4882,22 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
isBuiltinCall(c, "<unsafe-coerce>", "kotlin.jvm.internal") -> {
|
||||
|
||||
if (c.valueArgumentsCount != 1) {
|
||||
if (c.codeQlValueArgumentsCount != 1) {
|
||||
logger.errorElement(
|
||||
"Expected to find one argument for a kotlin.jvm.internal.<unsafe-coerce>() call, but found ${c.valueArgumentsCount}",
|
||||
"Expected to find one argument for a kotlin.jvm.internal.<unsafe-coerce>() call, but found ${c.codeQlValueArgumentsCount}",
|
||||
c
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (c.typeArgumentsCount != 2) {
|
||||
if (c.codeQlTypeArgumentsCount != 2) {
|
||||
logger.errorElement(
|
||||
"Expected to find two type arguments for a kotlin.jvm.internal.<unsafe-coerce>() call, but found ${c.typeArgumentsCount}",
|
||||
"Expected to find two type arguments for a kotlin.jvm.internal.<unsafe-coerce>() call, but found ${c.codeQlTypeArgumentsCount}",
|
||||
c
|
||||
)
|
||||
return
|
||||
}
|
||||
val valueArg = c.getValueArgument(0)
|
||||
val valueArg = c.codeQlGetValueArgument(0)
|
||||
if (valueArg == null) {
|
||||
logger.errorElement(
|
||||
"Cannot find value argument for a kotlin.jvm.internal.<unsafe-coerce>() call",
|
||||
@@ -4905,7 +4905,7 @@ open class KotlinFileExtractor(
|
||||
)
|
||||
return
|
||||
}
|
||||
val typeArg = c.getTypeArgument(1)
|
||||
val typeArg = c.codeQlGetTypeArgument(1)
|
||||
if (typeArg == null) {
|
||||
logger.errorElement(
|
||||
"Cannot find type argument for a kotlin.jvm.internal.<unsafe-coerce>() call",
|
||||
@@ -4924,7 +4924,7 @@ open class KotlinFileExtractor(
|
||||
extractExpressionExpr(valueArg, callable, id, 1, enclosingStmt)
|
||||
}
|
||||
isBuiltinCallInternal(c, "dataClassArrayMemberToString") -> {
|
||||
val arrayArg = c.getValueArgument(0)
|
||||
val arrayArg = c.codeQlGetValueArgument(0)
|
||||
val realArrayClass = arrayArg?.type?.classOrNull
|
||||
if (realArrayClass == null) {
|
||||
logger.errorElement(
|
||||
@@ -4936,8 +4936,8 @@ open class KotlinFileExtractor(
|
||||
val realCallee =
|
||||
javaUtilArrays?.declarations?.findSubType<IrFunction> { decl ->
|
||||
decl.name.asString() == "toString" &&
|
||||
decl.valueParameters.size == 1 &&
|
||||
decl.valueParameters[0].type.classOrNull?.let {
|
||||
decl.codeQlValueParameters.size == 1 &&
|
||||
decl.codeQlValueParameters[0].type.classOrNull?.let {
|
||||
it == realArrayClass
|
||||
} == true
|
||||
}
|
||||
@@ -4962,7 +4962,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
}
|
||||
isBuiltinCallInternal(c, "dataClassArrayMemberHashCode") -> {
|
||||
val arrayArg = c.getValueArgument(0)
|
||||
val arrayArg = c.codeQlGetValueArgument(0)
|
||||
val realArrayClass = arrayArg?.type?.classOrNull
|
||||
if (realArrayClass == null) {
|
||||
logger.errorElement(
|
||||
@@ -4974,8 +4974,8 @@ open class KotlinFileExtractor(
|
||||
val realCallee =
|
||||
javaUtilArrays?.declarations?.findSubType<IrFunction> { decl ->
|
||||
decl.name.asString() == "hashCode" &&
|
||||
decl.valueParameters.size == 1 &&
|
||||
decl.valueParameters[0].type.classOrNull?.let {
|
||||
decl.codeQlValueParameters.size == 1 &&
|
||||
decl.codeQlValueParameters[0].type.classOrNull?.let {
|
||||
it == realArrayClass
|
||||
} == true
|
||||
}
|
||||
@@ -5155,7 +5155,7 @@ open class KotlinFileExtractor(
|
||||
val type = useType(eType)
|
||||
val isAnonymous = eType.isAnonymous
|
||||
val locId = tw.getLocation(e)
|
||||
val valueArgs = (0 until e.valueArgumentsCount).map { e.getValueArgument(it) }
|
||||
val valueArgs = (0 until e.codeQlValueArgumentsCount).map { e.codeQlGetValueArgument(it) }
|
||||
|
||||
val id =
|
||||
if (
|
||||
@@ -5211,10 +5211,10 @@ open class KotlinFileExtractor(
|
||||
realCallTarget is IrConstructor &&
|
||||
realCallTarget.parentClassOrNull?.fqNameWhenAvailable?.asString() ==
|
||||
"kotlin.Enum" &&
|
||||
realCallTarget.valueParameters.size == 2 &&
|
||||
realCallTarget.valueParameters[0].type ==
|
||||
realCallTarget.codeQlValueParameters.size == 2 &&
|
||||
realCallTarget.codeQlValueParameters[0].type ==
|
||||
pluginContext.irBuiltIns.stringType &&
|
||||
realCallTarget.valueParameters[1].type == pluginContext.irBuiltIns.intType
|
||||
realCallTarget.codeQlValueParameters[1].type == pluginContext.irBuiltIns.intType
|
||||
) {
|
||||
|
||||
val id0 =
|
||||
@@ -5287,7 +5287,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
val args =
|
||||
(0 until e.typeArgumentsCount).map { e.getTypeArgument(it) }.requireNoNullsOrNull()
|
||||
(0 until e.codeQlTypeArgumentsCount).map { e.codeQlGetTypeArgument(it) }.requireNoNullsOrNull()
|
||||
if (args == null) {
|
||||
logger.warnElement("Found null type argument in enum constructor call", e)
|
||||
return
|
||||
@@ -5365,7 +5365,7 @@ open class KotlinFileExtractor(
|
||||
// Check for an expression like x = get(x).op(e):
|
||||
val opReceiver = updateRhs.dispatchReceiver
|
||||
if (isExpectedLhs(opReceiver)) {
|
||||
updateRhs.getValueArgument(0)
|
||||
updateRhs.codeQlGetValueArgument(0)
|
||||
} else null
|
||||
} else null
|
||||
}
|
||||
@@ -5560,7 +5560,7 @@ open class KotlinFileExtractor(
|
||||
"set"
|
||||
)
|
||||
) {
|
||||
val updateRhs0 = arraySetCall.getValueArgument(1)
|
||||
val updateRhs0 = arraySetCall.codeQlGetValueArgument(1)
|
||||
if (updateRhs0 == null) {
|
||||
logger.errorElement("Update RHS not found", e)
|
||||
return false
|
||||
@@ -6403,12 +6403,12 @@ open class KotlinFileExtractor(
|
||||
val ids = getLocallyVisibleFunctionLabels(e.function)
|
||||
val locId = tw.getLocation(e)
|
||||
|
||||
val ext = e.function.extensionReceiverParameter
|
||||
val ext = e.function.codeQlExtensionReceiverParameter
|
||||
val parameters =
|
||||
if (ext != null) {
|
||||
listOf(ext) + e.function.valueParameters
|
||||
listOf(ext) + e.function.codeQlValueParameters
|
||||
} else {
|
||||
e.function.valueParameters
|
||||
e.function.codeQlValueParameters
|
||||
}
|
||||
|
||||
var types = parameters.map { it.type }
|
||||
@@ -6670,7 +6670,7 @@ open class KotlinFileExtractor(
|
||||
is IrFunction -> {
|
||||
if (
|
||||
ownerParent.dispatchReceiverParameter == owner &&
|
||||
ownerParent.extensionReceiverParameter != null
|
||||
ownerParent.codeQlExtensionReceiverParameter != null
|
||||
) {
|
||||
|
||||
val ownerParent2 = ownerParent.parent
|
||||
@@ -7089,7 +7089,7 @@ open class KotlinFileExtractor(
|
||||
makeReceiverInfo(callableReferenceExpr.dispatchReceiver, 0)
|
||||
private val extensionReceiverInfo =
|
||||
makeReceiverInfo(
|
||||
callableReferenceExpr.extensionReceiver,
|
||||
callableReferenceExpr.codeQlExtensionReceiver,
|
||||
if (dispatchReceiverInfo == null) 0 else 1
|
||||
)
|
||||
|
||||
@@ -7627,8 +7627,8 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
|
||||
val expressionTypeArguments =
|
||||
(0 until propertyReferenceExpr.typeArgumentsCount).mapNotNull {
|
||||
propertyReferenceExpr.getTypeArgument(it)
|
||||
(0 until propertyReferenceExpr.codeQlTypeArgumentsCount).mapNotNull {
|
||||
propertyReferenceExpr.codeQlGetTypeArgument(it)
|
||||
}
|
||||
|
||||
val idPropertyRef = tw.getFreshIdLabel<DbPropertyref>()
|
||||
@@ -7808,7 +7808,7 @@ open class KotlinFileExtractor(
|
||||
* constructor(dispatchReceiver: TD, extensionReceiver: TE) {
|
||||
* super()
|
||||
* this.dispatchReceiver = dispatchReceiver
|
||||
* this.extensionReceiver = extensionReceiver
|
||||
* this.codeQlExtensionReceiver = extensionReceiver
|
||||
* }
|
||||
* fun invoke(a0:T0, a1:T1, ... aI: TI): R { return this.dispatchReceiver.FN(a0,a1,...,aI) } OR
|
||||
* fun invoke( a1:T1, ... aI: TI): R { return this.dispatchReceiver.FN(this.dispatchReceiver,a1,...,aI) } OR
|
||||
@@ -7829,7 +7829,7 @@ open class KotlinFileExtractor(
|
||||
|
||||
if (
|
||||
functionReferenceExpr.dispatchReceiver != null &&
|
||||
functionReferenceExpr.extensionReceiver != null
|
||||
functionReferenceExpr.codeQlExtensionReceiver != null
|
||||
) {
|
||||
logger.errorElement(
|
||||
"Unexpected: dispatchReceiver and extensionReceiver are both non-null",
|
||||
@@ -7840,7 +7840,7 @@ open class KotlinFileExtractor(
|
||||
|
||||
if (
|
||||
target.owner.dispatchReceiverParameter != null &&
|
||||
target.owner.extensionReceiverParameter != null
|
||||
target.owner.codeQlExtensionReceiverParameter != null
|
||||
) {
|
||||
logger.errorElement(
|
||||
"Unexpected: dispatch and extension parameters are both non-null",
|
||||
@@ -7899,8 +7899,8 @@ open class KotlinFileExtractor(
|
||||
null
|
||||
}
|
||||
expressionTypeArguments =
|
||||
(0 until functionReferenceExpr.typeArgumentsCount).mapNotNull {
|
||||
functionReferenceExpr.getTypeArgument(it)
|
||||
(0 until functionReferenceExpr.codeQlTypeArgumentsCount).mapNotNull {
|
||||
functionReferenceExpr.codeQlGetTypeArgument(it)
|
||||
}
|
||||
dispatchReceiverIdx = -1
|
||||
}
|
||||
@@ -7965,7 +7965,7 @@ open class KotlinFileExtractor(
|
||||
functionReferenceExpr,
|
||||
declarationParent,
|
||||
null,
|
||||
{ it.valueParameters.size == 1 }
|
||||
{ it.codeQlValueParameters.size == 1 }
|
||||
) {
|
||||
// The argument to FunctionReference's constructor is the function arity.
|
||||
extractConstantInteger(
|
||||
@@ -8572,7 +8572,7 @@ open class KotlinFileExtractor(
|
||||
reverse: Boolean = false
|
||||
) {
|
||||
val typeArguments =
|
||||
(0 until c.typeArgumentsCount).map { c.getTypeArgument(it) }.requireNoNullsOrNull()
|
||||
(0 until c.codeQlTypeArgumentsCount).map { c.codeQlGetTypeArgument(it) }.requireNoNullsOrNull()
|
||||
if (typeArguments == null) {
|
||||
logger.errorElement("Found a null type argument for a member access expression", c)
|
||||
} else {
|
||||
@@ -8923,11 +8923,11 @@ open class KotlinFileExtractor(
|
||||
tw.writeVariableBinding(lhsId, fieldId)
|
||||
|
||||
val parameters = mutableListOf<IrValueParameter>()
|
||||
val extParam = samMember.extensionReceiverParameter
|
||||
val extParam = samMember.codeQlExtensionReceiverParameter
|
||||
if (extParam != null) {
|
||||
parameters.add(extParam)
|
||||
}
|
||||
parameters.addAll(samMember.valueParameters)
|
||||
parameters.addAll(samMember.codeQlValueParameters)
|
||||
|
||||
fun extractArgument(
|
||||
p: IrValueParameter,
|
||||
@@ -9032,7 +9032,7 @@ open class KotlinFileExtractor(
|
||||
elementToReportOn: IrElement,
|
||||
declarationParent: IrDeclarationParent,
|
||||
compilerGeneratedKindOverride: CompilerGeneratedKinds? = null,
|
||||
superConstructorSelector: (IrFunction) -> Boolean = { it.valueParameters.isEmpty() },
|
||||
superConstructorSelector: (IrFunction) -> Boolean = { it.codeQlValueParameters.isEmpty() },
|
||||
extractSuperconstructorArgs: (Label<DbSuperconstructorinvocationstmt>) -> Unit = {},
|
||||
): Label<out DbClassorinterface> {
|
||||
// Write class
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
import com.github.codeql.utils.versions.codeQlAddAnnotations
|
||||
import org.jetbrains.kotlin.ir.types.classFqName
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
@@ -355,7 +355,7 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
|
||||
private fun propertySignature(p: IrProperty) =
|
||||
((p.getter ?: p.setter)?.extensionReceiverParameter?.let {
|
||||
((p.getter ?: p.setter)?.codeQlExtensionReceiverParameter?.let {
|
||||
useType(erase(it.type)).javaResult.signature
|
||||
} ?: "")
|
||||
|
||||
@@ -368,7 +368,7 @@ open class KotlinUsesExtractor(
|
||||
// useDeclarationParent -> useFunction
|
||||
// -> extractFunctionLaterIfExternalFileMember, which would result for `fun <T> f(t:
|
||||
// T) { ... }` for example.
|
||||
(listOfNotNull(d.extensionReceiverParameter) + d.valueParameters)
|
||||
(listOfNotNull(d.codeQlExtensionReceiverParameter) + d.codeQlValueParameters)
|
||||
.map { useType(erase(it.type)).javaResult.signature }
|
||||
.joinToString(separator = ",", prefix = "(", postfix = ")")
|
||||
is IrProperty -> propertySignature(d) + externalClassExtractor.propertySignature
|
||||
@@ -488,8 +488,8 @@ open class KotlinUsesExtractor(
|
||||
val result =
|
||||
replacementClass.declarations.findSubType<IrSimpleFunction> { replacementDecl ->
|
||||
replacementDecl.name == f.name &&
|
||||
replacementDecl.valueParameters.size == f.valueParameters.size &&
|
||||
replacementDecl.valueParameters.zip(f.valueParameters).all {
|
||||
replacementDecl.codeQlValueParameters.size == f.codeQlValueParameters.size &&
|
||||
replacementDecl.codeQlValueParameters.zip(f.codeQlValueParameters).all {
|
||||
erase(it.first.type) == erase(it.second.type)
|
||||
}
|
||||
}
|
||||
@@ -1265,7 +1265,7 @@ open class KotlinUsesExtractor(
|
||||
private fun getWildcardSuppressionDirective(t: IrAnnotationContainer): Boolean? =
|
||||
t.getAnnotation(jvmWildcardSuppressionAnnotation)?.let {
|
||||
@Suppress("USELESS_CAST") // `as? Boolean` is not needed for Kotlin < 2.1
|
||||
(it.getValueArgument(0) as? CodeQLIrConst<Boolean>)?.value as? Boolean ?: true
|
||||
(it.codeQlGetValueArgument(0) as? CodeQLIrConst<Boolean>)?.value as? Boolean ?: true
|
||||
}
|
||||
|
||||
private fun addJavaLoweringArgumentWildcards(
|
||||
@@ -1376,9 +1376,9 @@ open class KotlinUsesExtractor(
|
||||
f.parent,
|
||||
parentId,
|
||||
getFunctionShortName(f).nameInDB,
|
||||
(maybeParameterList ?: f.valueParameters).map { it.type },
|
||||
(maybeParameterList ?: f.codeQlValueParameters).map { it.type },
|
||||
getAdjustedReturnType(f),
|
||||
f.extensionReceiverParameter?.type,
|
||||
f.codeQlExtensionReceiverParameter?.type,
|
||||
getFunctionTypeParameters(f),
|
||||
classTypeArgsIncludingOuterClasses,
|
||||
overridesCollectionsMethodWithAlteredParameterTypes(f),
|
||||
@@ -1401,12 +1401,12 @@ open class KotlinUsesExtractor(
|
||||
// The name of the function; normally f.name.asString().
|
||||
name: String,
|
||||
// The types of the value parameters that the functions takes; normally
|
||||
// f.valueParameters.map { it.type }.
|
||||
// f.codeQlValueParameters.map { it.type }.
|
||||
parameterTypes: List<IrType>,
|
||||
// The return type of the function; normally f.returnType.
|
||||
returnType: IrType,
|
||||
// The extension receiver of the function, if any; normally
|
||||
// f.extensionReceiverParameter?.type.
|
||||
// f.codeQlExtensionReceiverParameter?.type.
|
||||
extensionParamType: IrType?,
|
||||
// The type parameters of the function. This does not include type parameters of enclosing
|
||||
// classes.
|
||||
@@ -1579,7 +1579,7 @@ open class KotlinUsesExtractor(
|
||||
parentClass.fqNameWhenAvailable?.asString() !=
|
||||
"java.util.concurrent.ConcurrentHashMap" ||
|
||||
getFunctionShortName(f).nameInDB != "keySet" ||
|
||||
f.valueParameters.isNotEmpty() ||
|
||||
f.codeQlValueParameters.isNotEmpty() ||
|
||||
f.returnType.classFqName?.asString() != "kotlin.collections.MutableSet"
|
||||
) {
|
||||
return f.returnType
|
||||
@@ -1587,7 +1587,7 @@ open class KotlinUsesExtractor(
|
||||
|
||||
val otherKeySet =
|
||||
parentClass.declarations.findSubType<IrFunction> {
|
||||
it.name.asString() == "keySet" && it.valueParameters.size == 1
|
||||
it.name.asString() == "keySet" && it.codeQlValueParameters.size == 1
|
||||
} ?: return f.returnType
|
||||
|
||||
return otherKeySet.returnType.codeQlWithHasQuestionMark(false)
|
||||
@@ -1695,8 +1695,8 @@ open class KotlinUsesExtractor(
|
||||
javaClass.declarations.findSubType<IrFunction> { decl ->
|
||||
!decl.isFakeOverride &&
|
||||
decl.name.asString() == jvmName &&
|
||||
decl.valueParameters.size == f.valueParameters.size &&
|
||||
decl.valueParameters.zip(f.valueParameters).all { p ->
|
||||
decl.codeQlValueParameters.size == f.codeQlValueParameters.size &&
|
||||
decl.codeQlValueParameters.zip(f.codeQlValueParameters).all { p ->
|
||||
erase(p.first.type).classifierOrNull ==
|
||||
erase(p.second.type).classifierOrNull
|
||||
}
|
||||
@@ -2125,7 +2125,7 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
|
||||
return if (t.arguments.isNotEmpty())
|
||||
t.addAnnotations(listOf(RawTypeAnnotation.annotationConstructor))
|
||||
t.codeQlAddAnnotations(listOf(RawTypeAnnotation.annotationConstructor))
|
||||
else t
|
||||
}
|
||||
}
|
||||
@@ -2153,7 +2153,7 @@ open class KotlinUsesExtractor(
|
||||
val idxOffset =
|
||||
if (
|
||||
declarationParent is IrFunction &&
|
||||
declarationParent.extensionReceiverParameter != null
|
||||
declarationParent.codeQlExtensionReceiverParameter != null
|
||||
)
|
||||
// For extension functions increase the index to match what the java extractor sees:
|
||||
1
|
||||
@@ -2187,7 +2187,7 @@ open class KotlinUsesExtractor(
|
||||
// Gets a field's corresponding property's extension receiver type, if any
|
||||
fun getExtensionReceiverType(f: IrField) =
|
||||
f.correspondingPropertySymbol?.owner?.let {
|
||||
(it.getter ?: it.setter)?.extensionReceiverParameter?.type
|
||||
(it.getter ?: it.setter)?.codeQlExtensionReceiverParameter?.type
|
||||
}
|
||||
|
||||
fun getFieldLabel(f: IrField): String {
|
||||
@@ -2222,14 +2222,14 @@ open class KotlinUsesExtractor(
|
||||
val setter = p.setter
|
||||
|
||||
val func = getter ?: setter
|
||||
val ext = func?.extensionReceiverParameter
|
||||
val ext = func?.codeQlExtensionReceiverParameter
|
||||
|
||||
return if (ext == null) {
|
||||
"@\"property;{$parentId};${p.name.asString()}\""
|
||||
} else {
|
||||
val returnType =
|
||||
getter?.returnType
|
||||
?: setter?.valueParameters?.singleOrNull()?.type
|
||||
?: setter?.codeQlValueParameters?.singleOrNull()?.type
|
||||
?: pluginContext.irBuiltIns.unitType
|
||||
val typeParams = getFunctionTypeParameters(func)
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.github.codeql
|
||||
|
||||
import com.github.codeql.utils.versions.codeQlAnnotationFromSymbolOwner
|
||||
import com.github.codeql.utils.versions.codeQlGetValueArgument
|
||||
import com.github.codeql.utils.versions.codeQlPutValueArgument
|
||||
import com.github.codeql.utils.versions.codeQlSetAnnotations
|
||||
import com.github.codeql.utils.versions.codeQlSetDispatchReceiverParameter
|
||||
import com.github.codeql.utils.versions.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||
import java.lang.annotation.ElementType
|
||||
import java.util.HashSet
|
||||
@@ -95,7 +100,7 @@ class MetaAnnotationSupport(
|
||||
JvmAnnotationNames.REPEATABLE_ANNOTATION
|
||||
}
|
||||
return if (jvmRepeatable != null) {
|
||||
((jvmRepeatable.getValueArgument(0) as? IrClassReference)?.symbol as? IrClassSymbol)
|
||||
((jvmRepeatable.codeQlGetValueArgument(0) as? IrClassReference)?.symbol as? IrClassSymbol)
|
||||
?.owner
|
||||
} else {
|
||||
getOrCreateSyntheticRepeatableAnnotationContainer(annotationClass)
|
||||
@@ -117,12 +122,12 @@ class MetaAnnotationSupport(
|
||||
)
|
||||
return null
|
||||
} else {
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
containerClass.defaultType,
|
||||
containerConstructor.symbol
|
||||
)
|
||||
.apply {
|
||||
putValueArgument(
|
||||
codeQlPutValueArgument(
|
||||
0,
|
||||
IrVarargImpl(
|
||||
UNDEFINED_OFFSET,
|
||||
@@ -144,7 +149,7 @@ class MetaAnnotationSupport(
|
||||
|
||||
// Taken from AdditionalClassAnnotationLowering.kt
|
||||
private fun loadAnnotationTargets(targetEntry: IrConstructorCall): Set<KotlinTarget>? {
|
||||
val valueArgument = targetEntry.getValueArgument(0) as? IrVararg ?: return null
|
||||
val valueArgument = targetEntry.codeQlGetValueArgument(0) as? IrVararg ?: return null
|
||||
return valueArgument.elements
|
||||
.filterIsInstance<IrGetEnumValue>()
|
||||
.mapNotNull { KotlinTarget.valueOrNull(it.symbol.owner.name.asString()) }
|
||||
@@ -230,14 +235,14 @@ class MetaAnnotationSupport(
|
||||
)
|
||||
}
|
||||
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
targetConstructor.returnType,
|
||||
targetConstructor.symbol,
|
||||
0
|
||||
)
|
||||
.apply { putValueArgument(0, vararg) }
|
||||
.apply { codeQlPutValueArgument(0, vararg) }
|
||||
}
|
||||
|
||||
private val javaAnnotationRetention by lazy {
|
||||
@@ -263,7 +268,7 @@ class MetaAnnotationSupport(
|
||||
// Taken from AnnotationCodegen.kt (not available in Kotlin < 1.6.20)
|
||||
private fun IrClass.getAnnotationRetention(): KotlinRetention? {
|
||||
val retentionArgument =
|
||||
getAnnotation(StandardNames.FqNames.retention)?.getValueArgument(0) as? IrGetEnumValue
|
||||
getAnnotation(StandardNames.FqNames.retention)?.codeQlGetValueArgument(0) as? IrGetEnumValue
|
||||
?: return null
|
||||
val retentionArgumentValue = retentionArgument.symbol.owner
|
||||
return KotlinRetention.valueOf(retentionArgumentValue.name.asString())
|
||||
@@ -283,7 +288,7 @@ class MetaAnnotationSupport(
|
||||
val targetConstructor =
|
||||
retentionType.declarations.firstIsInstanceOrNull<IrConstructor>() ?: return null
|
||||
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
targetConstructor.returnType,
|
||||
@@ -291,7 +296,7 @@ class MetaAnnotationSupport(
|
||||
0
|
||||
)
|
||||
.apply {
|
||||
putValueArgument(
|
||||
codeQlPutValueArgument(
|
||||
0,
|
||||
IrGetEnumValueImpl(
|
||||
UNDEFINED_OFFSET,
|
||||
@@ -333,7 +338,7 @@ class MetaAnnotationSupport(
|
||||
return
|
||||
}
|
||||
val newParam = thisReceiever.copyTo(this)
|
||||
dispatchReceiverParameter = newParam
|
||||
codeQlSetDispatchReceiverParameter(newParam)
|
||||
body =
|
||||
factory
|
||||
.createBlockBody(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
||||
@@ -406,7 +411,7 @@ class MetaAnnotationSupport(
|
||||
val repeatableContainerAnnotation =
|
||||
kotlinAnnotationRepeatableContainer?.constructors?.single()
|
||||
|
||||
containerClass.annotations =
|
||||
codeQlSetAnnotations(containerClass,
|
||||
annotationClass.annotations
|
||||
.filter {
|
||||
it.isAnnotationWithEqualFqName(StandardNames.FqNames.retention) ||
|
||||
@@ -415,7 +420,7 @@ class MetaAnnotationSupport(
|
||||
.map { it.deepCopyWithSymbols(containerClass) } +
|
||||
listOfNotNull(
|
||||
repeatableContainerAnnotation?.let {
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
it.returnType,
|
||||
@@ -424,6 +429,7 @@ class MetaAnnotationSupport(
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
containerClass
|
||||
}
|
||||
@@ -462,14 +468,14 @@ class MetaAnnotationSupport(
|
||||
containerClass.symbol,
|
||||
containerClass.defaultType
|
||||
)
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
repeatableConstructor.returnType,
|
||||
repeatableConstructor.symbol,
|
||||
0
|
||||
)
|
||||
.apply { putValueArgument(0, containerReference) }
|
||||
.apply { codeQlPutValueArgument(0, containerReference) }
|
||||
}
|
||||
|
||||
private val javaAnnotationDocumented by lazy {
|
||||
@@ -488,7 +494,7 @@ class MetaAnnotationSupport(
|
||||
javaAnnotationDocumented?.declarations?.firstIsInstanceOrNull<IrConstructor>()
|
||||
?: return null
|
||||
|
||||
return IrConstructorCallImpl.fromSymbolOwner(
|
||||
return codeQlAnnotationFromSymbolOwner(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
documentedConstructor.returnType,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.codeql
|
||||
|
||||
import com.github.codeql.KotlinUsesExtractor.LocallyVisibleFunctionLabels
|
||||
import com.github.codeql.utils.versions.codeQlExtensionReceiver
|
||||
import com.semmle.extractor.java.PopulateFile
|
||||
import com.semmle.util.unicode.UTF8Util
|
||||
import java.io.BufferedWriter
|
||||
@@ -331,7 +332,7 @@ open class FileTrapWriter(
|
||||
is IrCall -> {
|
||||
// Calls have incorrect startOffset, so we adjust them:
|
||||
val dr = e.dispatchReceiver?.let { getStartOffset(it) }
|
||||
val er = e.extensionReceiver?.let { getStartOffset(it) }
|
||||
val er = e.codeQlExtensionReceiver?.let { getStartOffset(it) }
|
||||
offsetMinOf(e.startOffset, dr, er)
|
||||
}
|
||||
else -> e.startOffset
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.github.codeql.comments
|
||||
|
||||
import com.github.codeql.*
|
||||
import com.github.codeql.utils.isLocalFunction
|
||||
import com.github.codeql.utils.versions.codeQlExtensionReceiverParameter
|
||||
import com.github.codeql.utils.versions.isDispatchReceiver
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -11,7 +12,7 @@ import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
||||
|
||||
private fun IrValueParameter.isExtensionReceiver(): Boolean {
|
||||
val parentFun = parent as? IrFunction ?: return false
|
||||
return parentFun.extensionReceiverParameter == this
|
||||
return parentFun.codeQlExtensionReceiverParameter == this
|
||||
}
|
||||
|
||||
open class CommentExtractor(
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.github.codeql.utils
|
||||
|
||||
import com.github.codeql.utils.versions.CodeQLIrConst
|
||||
import com.github.codeql.utils.versions.codeQlGetValueArgument
|
||||
import com.github.codeql.utils.versions.codeQlValueArgumentsCount
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
@@ -76,9 +78,9 @@ private fun getSpecialJvmName(f: IrFunction): String? {
|
||||
fun getJvmName(container: IrAnnotationContainer): String? {
|
||||
for (a: IrConstructorCall in container.annotations) {
|
||||
val t = a.type
|
||||
if (t is IrSimpleType && a.valueArgumentsCount == 1) {
|
||||
if (t is IrSimpleType && a.codeQlValueArgumentsCount == 1) {
|
||||
val owner = t.classifier.owner
|
||||
val v = a.getValueArgument(0)
|
||||
val v = a.codeQlGetValueArgument(0)
|
||||
if (owner is IrClass) {
|
||||
val aPkg = owner.packageFqName?.asString()
|
||||
val name = owner.name.asString()
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.DescriptorlessExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
import com.github.codeql.utils.versions.codeQlAddAnnotations
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.makeNotNull
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||
@@ -192,7 +192,7 @@ object RawTypeAnnotation {
|
||||
addConstructor { isPrimary = true }
|
||||
}
|
||||
val constructor = annoClass.constructors.single()
|
||||
IrConstructorCallImpl.fromSymbolOwner(constructor.constructedClassType, constructor.symbol)
|
||||
codeQlAnnotationFromSymbolOwner(constructor.constructedClassType, constructor.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ fun IrType.toRawType(): IrType =
|
||||
when (val owner = this.classifier.owner) {
|
||||
is IrClass -> {
|
||||
if (this.arguments.isNotEmpty())
|
||||
this.addAnnotations(listOf(RawTypeAnnotation.annotationConstructor))
|
||||
this.codeQlAddAnnotations(listOf(RawTypeAnnotation.annotationConstructor))
|
||||
else this
|
||||
}
|
||||
is IrTypeParameter -> owner.superTypes[0].toRawType()
|
||||
@@ -215,7 +215,7 @@ fun IrType.toRawType(): IrType =
|
||||
fun IrClass.toRawType(): IrType {
|
||||
val result = this.typeWith(listOf())
|
||||
return if (this.typeParameters.isNotEmpty())
|
||||
result.addAnnotations(listOf(RawTypeAnnotation.annotationConstructor))
|
||||
result.codeQlAddAnnotations(listOf(RawTypeAnnotation.annotationConstructor))
|
||||
else result
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
|
||||
/**
|
||||
* Compatibility accessors for pre-2.4.0 API patterns.
|
||||
* In pre-2.4.0 versions, these delegate directly to the existing APIs.
|
||||
*/
|
||||
|
||||
// IrFunction: valueParameters
|
||||
val IrFunction.codeQlValueParameters: List<IrValueParameter>
|
||||
get() = valueParameters
|
||||
|
||||
// IrFunction: extensionReceiverParameter
|
||||
val IrFunction.codeQlExtensionReceiverParameter: IrValueParameter?
|
||||
get() = extensionReceiverParameter
|
||||
|
||||
// IrMemberAccessExpression: valueArgumentsCount
|
||||
val IrMemberAccessExpression<*>.codeQlValueArgumentsCount: Int
|
||||
get() = valueArgumentsCount
|
||||
|
||||
// IrMemberAccessExpression: getValueArgument
|
||||
fun IrMemberAccessExpression<*>.codeQlGetValueArgument(index: Int): IrExpression? = getValueArgument(index)
|
||||
|
||||
// IrMemberAccessExpression: putValueArgument
|
||||
fun IrMemberAccessExpression<*>.codeQlPutValueArgument(index: Int, value: IrExpression?) {
|
||||
putValueArgument(index, value)
|
||||
}
|
||||
|
||||
// IrMemberAccessExpression: extensionReceiver
|
||||
var IrMemberAccessExpression<*>.codeQlExtensionReceiver: IrExpression?
|
||||
get() = extensionReceiver
|
||||
set(value) { extensionReceiver = value }
|
||||
|
||||
// IrMemberAccessExpression: typeArgumentsCount
|
||||
val IrMemberAccessExpression<*>.codeQlTypeArgumentsCount: Int
|
||||
get() = typeArgumentsCount
|
||||
|
||||
// IrMemberAccessExpression: getTypeArgument
|
||||
fun IrMemberAccessExpression<*>.codeQlGetTypeArgument(index: Int): IrType? = getTypeArgument(index)
|
||||
|
||||
// addAnnotations compat: in pre-2.4.0, addAnnotations expects List<IrConstructorCall>
|
||||
fun IrType.codeQlAddAnnotations(annotations: List<IrConstructorCall>): IrType =
|
||||
addAnnotations(annotations)
|
||||
|
||||
// IrMutableAnnotationContainer.annotations setter: in pre-2.4.0, annotations is var with List<IrConstructorCall>
|
||||
fun codeQlSetAnnotations(container: org.jetbrains.kotlin.ir.declarations.IrMutableAnnotationContainer, annotations: List<IrConstructorCall>) {
|
||||
container.annotations = annotations
|
||||
}
|
||||
|
||||
// IrFunction: set dispatch receiver parameter (pre-2.4.0 it's a var)
|
||||
fun IrFunction.codeQlSetDispatchReceiverParameter(param: IrValueParameter?) {
|
||||
dispatchReceiverParameter = param
|
||||
}
|
||||
|
||||
// In pre-2.4.0, annotations are List<IrConstructorCall> so IrConstructorCallImpl works directly.
|
||||
fun codeQlAnnotationFromSymbolOwner(
|
||||
startOffset: Int, endOffset: Int, type: IrType, symbol: IrConstructorSymbol, typeArgumentsCount: Int
|
||||
): IrConstructorCall =
|
||||
IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, symbol, typeArgumentsCount)
|
||||
|
||||
fun codeQlAnnotationFromSymbolOwner(type: IrType, symbol: IrConstructorSymbol): IrConstructorCall =
|
||||
IrConstructorCallImpl.fromSymbolOwner(type, symbol)
|
||||
@@ -3,10 +3,32 @@
|
||||
|
||||
package com.github.codeql
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.extensions.LoadingOrder
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
|
||||
@OptIn(ExperimentalCompilerApi::class)
|
||||
abstract class Kotlin2ComponentRegistrar : ComponentRegistrar {
|
||||
/* Nothing to do; supportsK2 doesn't exist yet. */
|
||||
|
||||
private var project: MockProject? = null
|
||||
|
||||
override fun registerProjectComponents(
|
||||
project: MockProject,
|
||||
configuration: CompilerConfiguration
|
||||
) {
|
||||
this.project = project
|
||||
doRegisterExtensions(configuration)
|
||||
}
|
||||
|
||||
abstract fun doRegisterExtensions(configuration: CompilerConfiguration)
|
||||
|
||||
fun registerExtractorExtension(extension: IrGenerationExtension) {
|
||||
val p = project ?: throw IllegalStateException("registerExtractorExtension called before registerProjectComponents")
|
||||
val extensionPoint = p.extensionArea.getExtensionPoint(IrGenerationExtension.extensionPointName)
|
||||
extensionPoint.registerExtension(extension, LoadingOrder.LAST, p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,35 @@
|
||||
|
||||
package com.github.codeql
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.extensions.LoadingOrder
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
|
||||
@OptIn(ExperimentalCompilerApi::class)
|
||||
abstract class Kotlin2ComponentRegistrar : ComponentRegistrar {
|
||||
override val supportsK2: Boolean
|
||||
get() = true
|
||||
|
||||
private var project: MockProject? = null
|
||||
|
||||
override fun registerProjectComponents(
|
||||
project: MockProject,
|
||||
configuration: CompilerConfiguration
|
||||
) {
|
||||
this.project = project
|
||||
doRegisterExtensions(configuration)
|
||||
}
|
||||
|
||||
abstract fun doRegisterExtensions(configuration: CompilerConfiguration)
|
||||
|
||||
fun registerExtractorExtension(extension: IrGenerationExtension) {
|
||||
val p = project ?: throw IllegalStateException("registerExtractorExtension called before registerProjectComponents")
|
||||
// Register with LoadingOrder.LAST to ensure the extractor runs after other
|
||||
// IR generation plugins (like kotlinx.serialization) have generated their code.
|
||||
val extensionPoint = p.extensionArea.getExtensionPoint(IrGenerationExtension.extensionPointName)
|
||||
extensionPoint.registerExtension(extension, LoadingOrder.LAST, p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.expressions.IrAnnotation
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrAnnotationImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.fromSymbolOwner
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
|
||||
/**
|
||||
* Compatibility accessors for pre-2.4.0 API patterns.
|
||||
* In 2.4.0, valueParameters/extensionReceiverParameter/extensionReceiver/
|
||||
* getValueArgument/putValueArgument/valueArgumentsCount/typeArgumentsCount/getTypeArgument
|
||||
* have been removed. This file provides the 2.4.0 implementations.
|
||||
*/
|
||||
|
||||
// IrFunction: valueParameters -> parameters filtered to Regular kind
|
||||
val IrFunction.codeQlValueParameters: List<IrValueParameter>
|
||||
get() = parameters.filter { it.kind == org.jetbrains.kotlin.ir.declarations.IrParameterKind.Regular }
|
||||
|
||||
// IrFunction: extensionReceiverParameter
|
||||
val IrFunction.codeQlExtensionReceiverParameter: IrValueParameter?
|
||||
get() = parameters.firstOrNull { it.kind == org.jetbrains.kotlin.ir.declarations.IrParameterKind.ExtensionReceiver }
|
||||
|
||||
// Helper: get the offset of value arguments in the arguments list
|
||||
// In 2.4.0, arguments[] includes dispatch/extension receivers before regular params
|
||||
private fun IrMemberAccessExpression<*>.valueArgumentOffset(): Int {
|
||||
val owner = symbol.owner as? IrFunction ?: return 0
|
||||
return owner.parameters.count { it.kind != org.jetbrains.kotlin.ir.declarations.IrParameterKind.Regular }
|
||||
}
|
||||
|
||||
// IrMemberAccessExpression: valueArgumentsCount
|
||||
val IrMemberAccessExpression<*>.codeQlValueArgumentsCount: Int
|
||||
get() = arguments.size - valueArgumentOffset()
|
||||
|
||||
// IrMemberAccessExpression: getValueArgument
|
||||
fun IrMemberAccessExpression<*>.codeQlGetValueArgument(index: Int): IrExpression? = arguments[index + valueArgumentOffset()]
|
||||
|
||||
// IrMemberAccessExpression: putValueArgument
|
||||
fun IrMemberAccessExpression<*>.codeQlPutValueArgument(index: Int, value: IrExpression?) {
|
||||
arguments[index + valueArgumentOffset()] = value
|
||||
}
|
||||
|
||||
// IrMemberAccessExpression: extensionReceiver
|
||||
var IrMemberAccessExpression<*>.codeQlExtensionReceiver: IrExpression?
|
||||
get() {
|
||||
val erp = symbol.owner.let { it as? IrFunction }?.codeQlExtensionReceiverParameter ?: return null
|
||||
return arguments[erp.indexInParameters]
|
||||
}
|
||||
set(value) {
|
||||
val erp = symbol.owner.let { it as? IrFunction }?.codeQlExtensionReceiverParameter ?: return
|
||||
arguments[erp.indexInParameters] = value
|
||||
}
|
||||
|
||||
// IrMemberAccessExpression: typeArgumentsCount
|
||||
val IrMemberAccessExpression<*>.codeQlTypeArgumentsCount: Int
|
||||
get() = typeArguments.size
|
||||
|
||||
// IrMemberAccessExpression: getTypeArgument
|
||||
fun IrMemberAccessExpression<*>.codeQlGetTypeArgument(index: Int): IrType? = typeArguments[index]
|
||||
|
||||
// addAnnotations compat: in 2.4.0, addAnnotations expects List<IrAnnotation>
|
||||
// IrAnnotation extends IrConstructorCall, so we cast
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun IrType.codeQlAddAnnotations(annotations: List<IrConstructorCall>): IrType =
|
||||
addAnnotations(annotations as List<IrAnnotation>)
|
||||
|
||||
// IrMutableAnnotationContainer.annotations setter: in 2.4.0, expects List<IrAnnotation>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun codeQlSetAnnotations(container: org.jetbrains.kotlin.ir.declarations.IrMutableAnnotationContainer, annotations: List<IrConstructorCall>) {
|
||||
container.annotations = annotations as List<IrAnnotation>
|
||||
}
|
||||
|
||||
// IrFunction: set dispatch receiver parameter
|
||||
// In 2.4.0, dispatchReceiverParameter is val; modify the parameters list directly.
|
||||
fun IrFunction.codeQlSetDispatchReceiverParameter(param: IrValueParameter?) {
|
||||
val existing = parameters.indexOfFirst { it.kind == org.jetbrains.kotlin.ir.declarations.IrParameterKind.DispatchReceiver }
|
||||
val mutableParams = parameters.toMutableList()
|
||||
if (existing >= 0) {
|
||||
if (param != null) {
|
||||
mutableParams[existing] = param
|
||||
} else {
|
||||
mutableParams.removeAt(existing)
|
||||
}
|
||||
} else if (param != null) {
|
||||
param.kind = org.jetbrains.kotlin.ir.declarations.IrParameterKind.DispatchReceiver
|
||||
mutableParams.add(0, param)
|
||||
}
|
||||
parameters = mutableParams
|
||||
}
|
||||
|
||||
// In 2.4.0, annotation lists require IrAnnotation instances.
|
||||
// Use IrAnnotationImpl.fromSymbolOwner instead of IrConstructorCallImpl.fromSymbolOwner.
|
||||
fun codeQlAnnotationFromSymbolOwner(
|
||||
startOffset: Int, endOffset: Int, type: IrType, symbol: IrConstructorSymbol, typeArgumentsCount: Int
|
||||
): IrConstructorCall =
|
||||
IrAnnotationImpl.fromSymbolOwner(startOffset, endOffset, type, symbol, typeArgumentsCount)
|
||||
|
||||
fun codeQlAnnotationFromSymbolOwner(type: IrType, symbol: IrConstructorSymbol): IrConstructorCall =
|
||||
IrAnnotationImpl.fromSymbolOwner(type, symbol)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
@file:Suppress("DEPRECATION", "DEPRECATION_ERROR")
|
||||
@file:OptIn(ExperimentalCompilerApi::class)
|
||||
|
||||
package com.github.codeql
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
|
||||
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
|
||||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
|
||||
abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar(), ComponentRegistrar {
|
||||
override val supportsK2: Boolean
|
||||
get() = true
|
||||
|
||||
override val pluginId: String
|
||||
get() = "com.github.codeql.kotlin-extractor"
|
||||
|
||||
// ComponentRegistrar implementation (legacy path, still called by Kotlin compiler)
|
||||
override fun registerProjectComponents(
|
||||
project: MockProject,
|
||||
configuration: CompilerConfiguration
|
||||
) {
|
||||
// In 2.4.0, we use CompilerPluginRegistrar path instead.
|
||||
// This is only called if the compiler uses the ComponentRegistrar service file.
|
||||
// We do nothing here since registerExtensions will be called separately.
|
||||
}
|
||||
|
||||
private var extensionStorage: CompilerPluginRegistrar.ExtensionStorage? = null
|
||||
private var registeredExtension: IrGenerationExtension? = null
|
||||
|
||||
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
|
||||
this@Kotlin2ComponentRegistrar.extensionStorage = this
|
||||
doRegisterExtensions(configuration)
|
||||
}
|
||||
|
||||
abstract fun doRegisterExtensions(configuration: CompilerConfiguration)
|
||||
|
||||
fun registerExtractorExtension(extension: IrGenerationExtension) {
|
||||
val storage = extensionStorage ?: throw IllegalStateException("registerExtractorExtension called before registerExtensions")
|
||||
with(storage) {
|
||||
IrGenerationExtension.registerExtension(extension)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrParameterKind
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
|
||||
fun parameterIndexExcludingReceivers(vp: IrValueParameter): Int {
|
||||
val offset =
|
||||
(vp.parent as? IrFunction)?.let { f ->
|
||||
f.parameters.count { it.kind == IrParameterKind.DispatchReceiver || it.kind == IrParameterKind.ExtensionReceiver || it.kind == IrParameterKind.Context }
|
||||
} ?: 0
|
||||
return vp.indexInParameters - offset
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
com.github.codeql.KotlinExtractorComponentRegistrar
|
||||
@@ -11,6 +11,7 @@ VERSIONS = [
|
||||
"2.2.20-Beta2",
|
||||
"2.3.0",
|
||||
"2.3.20",
|
||||
"2.4.0",
|
||||
]
|
||||
|
||||
def _version_to_tuple(v):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.3.30.",
|
||||
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.4.10.",
|
||||
"severity": "error",
|
||||
"source": {
|
||||
"extractorName": "java",
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Improved modeling of Apache HttpClient `execute` method sinks for `java/ssrf` and `java/non-https-url`.
|
||||
4
java/ql/lib/change-notes/2026-06-04-kotlin-2.4.0.md
Normal file
4
java/ql/lib/change-notes/2026-06-04-kotlin-2.4.0.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: feature
|
||||
---
|
||||
* Kotlin 2.4.0 can now be analysed.
|
||||
@@ -11,7 +11,7 @@ extensions:
|
||||
- ["org.apache.http.client.methods", "HttpPost", False, "HttpPost", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- ["org.apache.http.client.methods", "HttpPut", False, "HttpPut", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- ["org.apache.http.client.methods", "HttpRequestBase", True, "setURI", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- ["org.apache.http.client.methods", "HttpRequestWrapper", True, "setURI", "(URI)", "", "Argument[0]", "request-forgery", "hq-manual"]
|
||||
- ["org.apache.http.client.methods", "HttpRequestWrapper", True, "setURI", "(URI)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "HttpTrace", False, "HttpTrace", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", False, "delete", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", False, "get", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
@@ -22,3 +22,29 @@ extensions:
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", False, "put", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", False, "setUri", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", False, "trace", "", "", "Argument[0]", "request-forgery", "manual"]
|
||||
- addsTo:
|
||||
pack: codeql/java-all
|
||||
extensible: summaryModel
|
||||
data:
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "build", "()", "", "Argument[this]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "delete", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "delete", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "get", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "get", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "getUri", "()", "", "Argument[this]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "head", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "head", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "options", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "options", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "patch", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "patch", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "post", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "post", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "put", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "put", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "setUri", "(String)", "", "Argument[0]", "Argument[this]", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "setUri", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "setUri", "(URI)", "", "Argument[0]", "Argument[this]", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "setUri", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "trace", "(String)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
- ["org.apache.http.client.methods", "RequestBuilder", True, "trace", "(URI)", "", "Argument[0]", "ReturnValue", "taint", "ai-manual"]
|
||||
|
||||
@@ -3,6 +3,11 @@ extensions:
|
||||
pack: codeql/java-all
|
||||
extensible: sinkModel
|
||||
data:
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,ResponseHandler,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest,ResponseHandler)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpHost,HttpRequest,ResponseHandler,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,ResponseHandler)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
- ["org.apache.http.client", "HttpClient", True, "execute", "(HttpUriRequest,ResponseHandler,HttpContext)", "", "Argument[0]", "request-forgery", "ai-manual"]
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.methods.RequestBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class ApacheHttpClientExecuteSSRF extends HttpServlet {
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
try {
|
||||
|
||||
String source = request.getParameter("host"); // $ Source
|
||||
|
||||
HttpHost host = new HttpHost(source);
|
||||
HttpRequest req = new BasicHttpRequest("GET", "/");
|
||||
HttpUriRequest uriReq = RequestBuilder.get(source).build(); // $ Alert
|
||||
HttpContext context = null;
|
||||
HttpClient client = HttpClients.createDefault();
|
||||
ResponseHandler<Object> handler = null;
|
||||
|
||||
client.execute(host, req); // $ Alert
|
||||
client.execute(host, req, context); // $ Alert
|
||||
client.execute(host, req, handler); // $ Alert
|
||||
client.execute(host, req, handler, context); // $ Alert
|
||||
client.execute(uriReq); // $ Alert
|
||||
client.execute(uriReq, context); // $ Alert
|
||||
client.execute(uriReq, handler); // $ Alert
|
||||
client.execute(uriReq, handler, context); // $ Alert
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
//semmle-extractor-options: --javac-args -source 11 -target 11 -cp ${testdir}/../../../stubs/javax-validation-constraints:${testdir}/../../../stubs/springframework-5.8.x:${testdir}/../../../stubs/javax-ws-rs-api-2.1.1:${testdir}/../../../stubs/javax-ws-rs-api-3.0.0:${testdir}/../../../stubs/apache-http-4.4.13/:${testdir}/../../../stubs/projectreactor-3.4.3/:${testdir}/../../../stubs/postgresql-42.3.3/:${testdir}/../../../stubs/HikariCP-3.4.5/:${testdir}/../../../stubs/spring-jdbc-5.3.8/:${testdir}/../../../stubs/jdbi3-core-3.27.2/:${testdir}/../../../stubs/cargo:${testdir}/../../../stubs/javafx-web:${testdir}/../../../stubs/apache-commons-jelly-1.0.1:${testdir}/../../../stubs/dom4j-2.1.1:${testdir}/../../../stubs/jaxen-1.2.0:${testdir}/../../../stubs/stapler-1.263:${testdir}/../../../stubs/javax-servlet-2.5:${testdir}/../../../stubs/apache-commons-fileupload-1.4:${testdir}/../../../stubs/saxon-xqj-9.x:${testdir}/../../../stubs/apache-commons-beanutils:${testdir}/../../../stubs/apache-commons-lang:${testdir}/../../../stubs/apache-http-5:${testdir}/../../../stubs/playframework-2.6.x:${testdir}/../../../stubs/jaxws-api-2.0:${testdir}/../../../stubs/apache-cxf
|
||||
//semmle-extractor-options: --javac-args -source 11 -target 11 -cp ${testdir}/../../../stubs/javax-validation-constraints:${testdir}/../../../stubs/springframework-5.8.x:${testdir}/../../../stubs/javax-ws-rs-api-2.1.1:${testdir}/../../../stubs/javax-ws-rs-api-3.0.0:${testdir}/../../../stubs/apache-http-4.4.13/:${testdir}/../../../stubs/apache-http-client-4.4.13:${testdir}/../../../stubs/projectreactor-3.4.3/:${testdir}/../../../stubs/postgresql-42.3.3/:${testdir}/../../../stubs/HikariCP-3.4.5/:${testdir}/../../../stubs/spring-jdbc-5.3.8/:${testdir}/../../../stubs/jdbi3-core-3.27.2/:${testdir}/../../../stubs/cargo:${testdir}/../../../stubs/javafx-web:${testdir}/../../../stubs/apache-commons-jelly-1.0.1:${testdir}/../../../stubs/dom4j-2.1.1:${testdir}/../../../stubs/jaxen-1.2.0:${testdir}/../../../stubs/stapler-1.263:${testdir}/../../../stubs/javax-servlet-2.5:${testdir}/../../../stubs/apache-commons-fileupload-1.4:${testdir}/../../../stubs/saxon-xqj-9.x:${testdir}/../../../stubs/apache-commons-beanutils:${testdir}/../../../stubs/apache-commons-lang:${testdir}/../../../stubs/apache-http-5:${testdir}/../../../stubs/playframework-2.6.x:${testdir}/../../../stubs/jaxws-api-2.0:${testdir}/../../../stubs/apache-cxf
|
||||
|
||||
23
java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/HttpClient.java
generated
Normal file
23
java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/HttpClient.java
generated
Normal file
@@ -0,0 +1,23 @@
|
||||
// Generated automatically from org.apache.http.client.HttpClient for testing purposes
|
||||
|
||||
package org.apache.http.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
public interface HttpClient {
|
||||
HttpResponse execute(HttpHost target, HttpRequest request) throws IOException;
|
||||
HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException;
|
||||
<T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler) throws IOException;
|
||||
<T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
|
||||
throws IOException;
|
||||
HttpResponse execute(HttpUriRequest request) throws IOException;
|
||||
HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException;
|
||||
<T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException;
|
||||
<T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
|
||||
throws IOException;
|
||||
}
|
||||
9
java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/ResponseHandler.java
generated
Normal file
9
java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/client/ResponseHandler.java
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
// Generated automatically from org.apache.http.client.ResponseHandler for testing purposes
|
||||
|
||||
package org.apache.http.client;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
|
||||
public interface ResponseHandler<T> {
|
||||
T handleResponse(HttpResponse response);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.apache.http.impl.client;
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
|
||||
public abstract class CloseableHttpClient implements HttpClient {
|
||||
|
||||
}
|
||||
10
java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/impl/client/HttpClients.java
generated
Normal file
10
java/ql/test/stubs/apache-http-client-4.4.13/org/apache/http/impl/client/HttpClients.java
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
// Generated automatically from org.apache.http.client.HttpClient for testing purposes
|
||||
|
||||
package org.apache.http.impl.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
|
||||
public final class HttpClients {
|
||||
public static CloseableHttpClient createDefault() { return null; }
|
||||
}
|
||||
@@ -21,13 +21,19 @@ file_coverage_languages:
|
||||
scc_languages:
|
||||
- TypeScript
|
||||
- TypeScript Typings
|
||||
- name: vue
|
||||
display_name: Vue.js component
|
||||
scc_languages:
|
||||
- Vue
|
||||
github_api_languages:
|
||||
- JavaScript
|
||||
- TypeScript
|
||||
- Vue
|
||||
scc_languages:
|
||||
- JavaScript
|
||||
- TypeScript
|
||||
- TypeScript Typings
|
||||
- Vue
|
||||
file_types:
|
||||
- name: javascript
|
||||
display_name: JavaScript
|
||||
|
||||
@@ -45,6 +45,7 @@ fn property_name(type_name: &str, field_name: &str) -> String {
|
||||
(_, "ty") => "type_repr",
|
||||
("Function", "body") => "function_body",
|
||||
("ClosureExpr", "body") => "closure_body",
|
||||
("Impl", "trait_") => "trait_ty",
|
||||
_ if field_name.contains("record") => &field_name.replacen("record", "struct", 1),
|
||||
_ => field_name,
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
description: Renamed `impl_trait_ties` to `impl_traits`
|
||||
compatibility: full
|
||||
|
||||
impl_traits.rel: reorder impl_trait_ties(@impl id, @type_repr trait_ty) id trait_ty
|
||||
impl_trait_ties.rel: delete
|
||||
2
rust/extractor/src/generated/.generated.list
generated
2
rust/extractor/src/generated/.generated.list
generated
@@ -1,2 +1,2 @@
|
||||
mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7
|
||||
top.rs ea9c28694da3d0e90d09fc7d31824e35817c34720ea91e7c8bf8e7e74ffe4ee8 ea9c28694da3d0e90d09fc7d31824e35817c34720ea91e7c8bf8e7e74ffe4ee8
|
||||
top.rs 2e8e3b4e42b172708bb3a6ec3a92a6577c576887019603ca3d0f045bbdbfdbac 2e8e3b4e42b172708bb3a6ec3a92a6577c576887019603ca3d0f045bbdbfdbac
|
||||
|
||||
6
rust/extractor/src/generated/top.rs
generated
6
rust/extractor/src/generated/top.rs
generated
@@ -9451,7 +9451,7 @@ pub struct Impl {
|
||||
pub is_default: bool,
|
||||
pub is_unsafe: bool,
|
||||
pub self_ty: Option<trap::Label<TypeRepr>>,
|
||||
pub trait_: Option<trap::Label<TypeRepr>>,
|
||||
pub trait_ty: Option<trap::Label<TypeRepr>>,
|
||||
pub visibility: Option<trap::Label<Visibility>>,
|
||||
pub where_clause: Option<trap::Label<WhereClause>>,
|
||||
}
|
||||
@@ -9484,8 +9484,8 @@ impl trap::TrapEntry for Impl {
|
||||
if let Some(v) = self.self_ty {
|
||||
out.add_tuple("impl_self_ties", vec![id.into(), v.into()]);
|
||||
}
|
||||
if let Some(v) = self.trait_ {
|
||||
out.add_tuple("impl_traits", vec![id.into(), v.into()]);
|
||||
if let Some(v) = self.trait_ty {
|
||||
out.add_tuple("impl_trait_ties", vec![id.into(), v.into()]);
|
||||
}
|
||||
if let Some(v) = self.visibility {
|
||||
out.add_tuple("impl_visibilities", vec![id.into(), v.into()]);
|
||||
|
||||
4
rust/extractor/src/translate/generated.rs
generated
4
rust/extractor/src/translate/generated.rs
generated
@@ -1229,7 +1229,7 @@ impl Translator<'_> {
|
||||
let is_default = node.default_token().is_some();
|
||||
let is_unsafe = node.unsafe_token().is_some();
|
||||
let self_ty = node.self_ty().and_then(|x| self.emit_type(&x));
|
||||
let trait_ = node.trait_().and_then(|x| self.emit_type(&x));
|
||||
let trait_ty = node.trait_().and_then(|x| self.emit_type(&x));
|
||||
let visibility = node.visibility().and_then(|x| self.emit_visibility(&x));
|
||||
let where_clause = node.where_clause().and_then(|x| self.emit_where_clause(&x));
|
||||
let label = self.trap.emit(generated::Impl {
|
||||
@@ -1241,7 +1241,7 @@ impl Translator<'_> {
|
||||
is_default,
|
||||
is_unsafe,
|
||||
self_ty,
|
||||
trait_,
|
||||
trait_ty,
|
||||
visibility,
|
||||
where_clause,
|
||||
});
|
||||
|
||||
11
rust/ql/.generated.list
generated
11
rust/ql/.generated.list
generated
@@ -69,7 +69,7 @@ lib/codeql/rust/elements/GenericParam.qll 87adf96aac385f2a182008a7b90aad46cf46d7
|
||||
lib/codeql/rust/elements/GenericParamList.qll 25fcaa68bc7798d75974d12607fae0afc7f84d43091b2d0c66a504095ef05667 3b71115c6af0b8e7f84d8c2d5ac9f23595ad2b22dbd19a9ea71906ca99340878
|
||||
lib/codeql/rust/elements/IdentPat.qll ad5f202316d4eeee3ca81ea445728f4ad7eb6bb7d81232bc958c22a93d064bf2 7ce2772e391e593d8fd23b2b44e26d0d7e780327ec973fcc9dce52a75fda0e36
|
||||
lib/codeql/rust/elements/IfExpr.qll f62153e8098b3eb08b569d4e25c750bc686665651579db4bc9e11dcef8e75d63 55006a55d612f189e73caa02f7b4deda388c692f0a801cdda9f833f2afdca778
|
||||
lib/codeql/rust/elements/Impl.qll ce5225fd97b184db7235bcf2561cf23c679de2fc96fecaeb8cbcf7935dd48fbd 3fe755118c3d0b1eb626f359da362ad75dbdcd1e09f09825b10038fb41ddb35c
|
||||
lib/codeql/rust/elements/Impl.qll 0d69c9ace5dac87ed095cfd5d4a8baf7e17ebce1132f3a7d6fa2bf4325deff8d d908fc5da7d3a59fb0a286a6ce581bdabdb48c4ac6ecd070455c271c2352208c
|
||||
lib/codeql/rust/elements/ImplTraitTypeRepr.qll 1d559b16c659f447a1bde94cc656718f20f133f767060437b755ac81eea9f852 de69c596701f0af4db28c5802d092a39c88a90bf42ea85aea25eecb79417e454
|
||||
lib/codeql/rust/elements/IndexExpr.qll 0e2e9f018d06ae72be0fc4ddbc019a9aacd8a06f42b4c4431760bd149e7f2290 2bcfd557abd53a48e48de7915c4f2089107c62dfb3e732a904848248dfd3727b
|
||||
lib/codeql/rust/elements/InferTypeRepr.qll 1b8bdcb574a7b6e7dd49f4cfb96655a6ccc355744b424b8c2593fe8218090d53 c20a2a5b0346dc277721deb450e732a47812c8e872ffb60aaba351b1708e9477
|
||||
@@ -373,7 +373,6 @@ lib/codeql/rust/elements/internal/SliceTypeReprImpl.qll ba1a53a3ecc90a7f54c003fc
|
||||
lib/codeql/rust/elements/internal/SourceFileConstructor.qll 1dc559887ea7798774528b5505c8601c61030c17480f7ffca49b68b76fcc0321 75a635b88622e3110b16795bd12ca6fc4af176c92d6e441518d60aa47255edc1
|
||||
lib/codeql/rust/elements/internal/SourceFileImpl.qll 829cc59d508c190fecfcfb0e27df232fd0a53cb98a6c6f110aecc7242db6f794 2834ab836557ae294410ccde023cca6ef6315aa4b78a7c238862437cec697583
|
||||
lib/codeql/rust/elements/internal/StaticConstructor.qll 6dd7ee3fd16466c407de35b439074b56341fc97a9c36846b725c2eb43fd4a643 5bf5b0e78d0e9eb294a57b91075de6e4b86a9e6335f546c83ec11ab4c51e5679
|
||||
lib/codeql/rust/elements/internal/StaticImpl.qll 48071e29c72032b59ad82771d54be92ac0f4c1a68fb1129c5c7991385804d7b1 85c0be8e37a91d6e775b191f0cb52dd8bf70418e6e9947b82c58c40a6d73b406
|
||||
lib/codeql/rust/elements/internal/StmtImpl.qll ea99d261f32592ff368cc3a1960864989897c92944f1675549e0753964cb562f 9117b4cdfad56f8fa3bc5d921c2146b4ff0658e8914ac51bf48eb3e68599dd6b
|
||||
lib/codeql/rust/elements/internal/StmtListConstructor.qll 435d59019e17a6279110a23d3d5dfbc1d1e16fc358a93a1d688484d22a754866 23fcb60a5cbb66174e459bc10bd7c28ed532fd1ab46f10b9f0c8a6291d3e343f
|
||||
lib/codeql/rust/elements/internal/StructConstructor.qll 52921ea6e70421fd08884dc061d0c2dfbbb8dd83d98f1f3c70572cfe57b2a173 dcb3ea8e45ee875525c645fe5d08e6db9013b86bd351c77df4590d0c1439ab9f
|
||||
@@ -511,7 +510,7 @@ lib/codeql/rust/elements/internal/generated/GenericParam.qll 85ac027a42b3300febc
|
||||
lib/codeql/rust/elements/internal/generated/GenericParamList.qll b18fa5fd435d94857c9863bbcc40571af0b1efba1b31ba9159c95568f5c58fce 6e70f1e9a1823d28d60e0e753ac8fbbe8deb10c94365f893b0c8f8ea4061b460
|
||||
lib/codeql/rust/elements/internal/generated/IdentPat.qll 1fe5061759848fdc9588b27606efb1187ce9c13d12ad0a2a19666d250dd62db3 87dbc8b88c31079076a896b48e0c483a600d7d11c1c4bf266581bdfc9c93ae98
|
||||
lib/codeql/rust/elements/internal/generated/IfExpr.qll 413dd7a20c6b98c0d2ad2e5b50981c14bf96c1a719ace3e341d78926219a5af7 c9a2d44e3baa6a265a29a683ca3c1683352457987c92f599c5771b4f3b4bafff
|
||||
lib/codeql/rust/elements/internal/generated/Impl.qll 5afadb7f80c5ffbd5cd3816c6788ccb605fe4cb2d8c8507ec3f212913eac0ab5 761b72a5f35e2e766de6aa87d83b065f49b64f05b91ae47d0afbb20bb61c1003
|
||||
lib/codeql/rust/elements/internal/generated/Impl.qll bdc3da08b23ab098e92927a57c2e99eeb78ea8561cf11accc51db3033492b500 4b45be6b0c51f03999619705104574d78c262ed2497921f2ca8696844b17addc
|
||||
lib/codeql/rust/elements/internal/generated/ImplTraitTypeRepr.qll e376a2e34ba51df403d42b02afe25140543e3e53aaf04b9ea118eb575acb4644 dc3a7e3eac758423c90a9803cc40dfdf53818bd62ee894982cd636f6b1596dfc
|
||||
lib/codeql/rust/elements/internal/generated/IndexExpr.qll cf951fc40f6690e966b4dc78fa9a6221aa5c6cade44759dcb52254f799292d11 1572e71918cc4e0b7e028331b6d98c9db23100a3646cd3874d1915e06ab6211d
|
||||
lib/codeql/rust/elements/internal/generated/InferTypeRepr.qll 4f101c1cb1278e919f9195cac4aa0c768e304c1881394b500874e7627e62d6c4 dca3f85d0a78ecc8bf030b4324f0d219ffff60784a2ecf565a4257e888dea0ff
|
||||
@@ -557,7 +556,7 @@ lib/codeql/rust/elements/internal/generated/ParamList.qll eaa0cd4402d3665013d47e
|
||||
lib/codeql/rust/elements/internal/generated/ParenExpr.qll 812d2ff65079277f39f15c084657a955a960a7c1c0e96dd60472a58d56b945eb eb8c607f43e1fcbb41f37a10de203a1db806690e10ff4f04d48ed874189cb0eb
|
||||
lib/codeql/rust/elements/internal/generated/ParenPat.qll 24f9dc7fce75827d6fddb856cd48f80168143151b27295c0bab6db5a06567a09 ebadbc6f5498e9ed754b39893ce0763840409a0721036a25b56e1ead7dcc09aa
|
||||
lib/codeql/rust/elements/internal/generated/ParenTypeRepr.qll 03f5c5b96a37adeb845352d7fcea3e098da9050e534972d14ac0f70d60a2d776 ed3d6e5d02086523087adebce4e89e35461eb95f2a66d1d4100fe23fc691b126
|
||||
lib/codeql/rust/elements/internal/generated/ParentChild.qll b0e3c13b2ca75faaf0d92b2ca3d70cac7b78b3729aaccf635063cc5836c163af a340e8f34a6d7425f38845e789b4aeb83aec90c11429a68ad6632a5aa132fa57
|
||||
lib/codeql/rust/elements/internal/generated/ParentChild.qll dc5e9e16e0d43cf25ebdce03b84aa3bf0f52fe0c61de4db4a9887c961290b37e b26f0f2c27b664d0fe53aba35955df31a58adad0963a951039b6c6bbd34f83ea
|
||||
lib/codeql/rust/elements/internal/generated/ParenthesizedArgList.qll d901fdc8142a5b8847cc98fc2afcfd16428b8ace4fbffb457e761b5fd3901a77 5dbb0aea5a13f937da666ccb042494af8f11e776ade1459d16b70a4dd193f9fb
|
||||
lib/codeql/rust/elements/internal/generated/Pat.qll 3605ac062be2f294ee73336e9669027b8b655f4ad55660e1eab35266275154ee 7f9400db2884d336dd1d21df2a8093759c2a110be9bf6482ce8e80ae0fd74ed4
|
||||
lib/codeql/rust/elements/internal/generated/Path.qll 9b12afb46fc5a9ad3a811b05472621bbecccb900c47504feb7f29d96b28421ca bcacbffc36fb3e0c9b26523b5963af0ffa9fd6b19f00a2a31bdb2316071546bd
|
||||
@@ -572,7 +571,7 @@ lib/codeql/rust/elements/internal/generated/PtrTypeRepr.qll 8d0ea4f6c7f8203340bf
|
||||
lib/codeql/rust/elements/internal/generated/PureSynthConstructors.qll e5b8e69519012bbaae29dcb82d53f7f7ecce368c0358ec27ef6180b228a0057f e5b8e69519012bbaae29dcb82d53f7f7ecce368c0358ec27ef6180b228a0057f
|
||||
lib/codeql/rust/elements/internal/generated/RangeExpr.qll 23cca03bf43535f33b22a38894f70d669787be4e4f5b8fe5c8f7b964d30e9027 18624cef6c6b679eeace2a98737e472432e0ead354cca02192b4d45330f047c9
|
||||
lib/codeql/rust/elements/internal/generated/RangePat.qll 80826a6a6868a803aa2372e31c52a03e1811a3f1f2abdb469f91ca0bfdd9ecb6 34ee1e208c1690cba505dff2c588837c0cd91e185e2a87d1fe673191962276a9
|
||||
lib/codeql/rust/elements/internal/generated/Raw.qll 6e32bd7167d3eece2d22f893a92410129b1bd18e59533b1cf82f72f31465b43a bb25c56118df0e2755be2350cf307c19e6c4d85b2a39388c08f2cc1bad303692
|
||||
lib/codeql/rust/elements/internal/generated/Raw.qll 6e38ac8ae1fbd7af0dd516f1c37e52e6ef1169103ad7dd998796ff8cd2dbac7a f4a7515e1757404b101ea3c8bb154d11d1babb138cb2afddf1618eab377d9625
|
||||
lib/codeql/rust/elements/internal/generated/RefExpr.qll 7d995884e3dc1c25fc719f5d7253179344d63650e217e9ff6530285fe7a57f64 f2c3c12551deea4964b66553fb9b6423ee16fec53bd63db4796191aa60dc6c66
|
||||
lib/codeql/rust/elements/internal/generated/RefPat.qll 456ede39837463ee22a630ec7ab6c8630d3664a8ea206fcc6e4f199e92fa564c 5622062765f32930465ba6b170e986706f159f6070f48adee3c20e24e8df4e05
|
||||
lib/codeql/rust/elements/internal/generated/RefTypeRepr.qll 5b0663a6d234572fb3e467e276d019415caa95ef006438cc59b7af4e1783161e 0e27c8a8f0e323c0e4d6db01fca821bf07c0864d293cdf96fa891b10820c1e4b
|
||||
@@ -692,7 +691,7 @@ test/extractor-tests/generated/GenericArgList/GenericArgList.ql 9bd6873e56a381a6
|
||||
test/extractor-tests/generated/GenericParamList/GenericParamList.ql 206f270690f5c142777d43cf87b65d6dda5ec9f3953c17ee943fe3d0e7b7761c 38a6e0bbca916778f85b106609df6d5929baed006d55811ec0d71c75fe137e92
|
||||
test/extractor-tests/generated/IdentPat/IdentPat.ql 23006eddf0ca1188e11ba5ee25ad62a83157b83e0b99119bf924c7f74fd8e70d 6e572f48f607f0ced309113304019ccc0a828f6ddd71e818369504dcf832a0b5
|
||||
test/extractor-tests/generated/IfExpr/IfExpr.ql 540b21838ad3e1ed879b66c1903eb8517d280f99babcbf3c5307c278db42f003 a6f84a7588ce7587936f24375518a365c571210844b99cb614596e14dd5e4dfd
|
||||
test/extractor-tests/generated/Impl/Impl.ql a36ea392729a6be3ee0cc0d8871b3682cf8f0c15fb657d4d35f2ca76eeef3a74 1fa345ca3b4c16c740b5684c7fdaf1116d52c2932287703b33143a08e4d7d38e
|
||||
test/extractor-tests/generated/Impl/Impl.ql c96ec30d703aa607b7aad9f6eaca1b0069799cdefcc1481f4aa4f7378f477f7f 3528e1502b6f7b323d964630ecfb8255f683486b75300457e2a2d95aa36771f3
|
||||
test/extractor-tests/generated/ImplTraitTypeRepr/ImplTraitTypeRepr.ql 311c6c1e18bd74fbcd367f940d2cf91777eaba6b3d6307149beb529216d086fb 16c7c81618d7f49da30b4f026dcacfb23ed130dbfcfa19b5cb44dc6e15101401
|
||||
test/extractor-tests/generated/IndexExpr/IndexExpr.ql ecfca80175a78b633bf41684a0f8f5eebe0b8a23f8de9ff27142936687711263 27d4832911f7272376a199550d57d8488e75e0eeeeb7abbfb3b135350a30d277
|
||||
test/extractor-tests/generated/InferTypeRepr/InferTypeRepr.ql 6ba01a9e229e7dfdb2878a0bdbeb6c0888c4a068984b820e7a48d4b84995daa2 7120cafd267e956dbb4af5e19d57237275d334ffe5ff0fb635d65d309381aa46
|
||||
|
||||
1
rust/ql/.gitattributes
generated
vendored
1
rust/ql/.gitattributes
generated
vendored
@@ -375,7 +375,6 @@
|
||||
/lib/codeql/rust/elements/internal/SourceFileConstructor.qll linguist-generated
|
||||
/lib/codeql/rust/elements/internal/SourceFileImpl.qll linguist-generated
|
||||
/lib/codeql/rust/elements/internal/StaticConstructor.qll linguist-generated
|
||||
/lib/codeql/rust/elements/internal/StaticImpl.qll linguist-generated
|
||||
/lib/codeql/rust/elements/internal/StmtImpl.qll linguist-generated
|
||||
/lib/codeql/rust/elements/internal/StmtListConstructor.qll linguist-generated
|
||||
/lib/codeql/rust/elements/internal/StructConstructor.qll linguist-generated
|
||||
|
||||
@@ -99,6 +99,8 @@ class FormatTemplateVariableAccessTree extends LeafTree, FormatTemplateVariableA
|
||||
class ItemTree extends LeafTree, Item {
|
||||
ItemTree() {
|
||||
not this instanceof MacroCall and
|
||||
not this instanceof Const and
|
||||
not this instanceof Static and
|
||||
this = any(StmtList s).getAStatement()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,3 +45,14 @@ final class CallableScope extends CfgScopeImpl, Callable {
|
||||
/** Holds if `scope` is exited when `last` finishes with completion `c`. */
|
||||
override predicate scopeLast(AstNode last, Completion c) { last(this.getBody(), last, c) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A special scope used to represent the context in which `const`s and
|
||||
* `static`s are initialized. We do not actually compute a CFG for such
|
||||
* scopes.
|
||||
*/
|
||||
final class SourceFileScope extends CfgScopeImpl, SourceFile {
|
||||
override predicate scopeFirst(AstNode first) { none() }
|
||||
|
||||
override predicate scopeLast(AstNode last, Completion c) { none() }
|
||||
}
|
||||
|
||||
@@ -653,8 +653,22 @@ module RustDataFlowGen<RustDataFlowInputSig Input> implements InputSig<Location>
|
||||
*/
|
||||
predicate jumpStep(Node node1, Node node2) {
|
||||
FlowSummaryImpl::Private::Steps::summaryJumpStep(node1.(FlowSummaryNode).getSummaryNode(),
|
||||
node2.(FlowSummaryNode).getSummaryNode()) or
|
||||
node2.(FlowSummaryNode).getSummaryNode())
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::sourceJumpStep(node1.(FlowSummaryNode).getSummaryNode(), node2)
|
||||
or
|
||||
exists(Const c |
|
||||
node1.asExpr() = c.getBody() and
|
||||
node2.asExpr() = c.getAnAccess()
|
||||
)
|
||||
or
|
||||
exists(StaticNode sn, Static s | s = sn.getStatic() |
|
||||
node1 = sn and
|
||||
node2.asExpr() = s.getAnAccess().(StaticReadAccess)
|
||||
or
|
||||
node1.asExpr() = [s.getBody(), s.getAnAccess().(StaticWriteAccess)] and
|
||||
node2 = sn
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
|
||||
@@ -704,6 +704,17 @@ final class CastNode extends ExprNode {
|
||||
CastNode() { none() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A node in the data flow graph that corresponds to a `static`.
|
||||
*/
|
||||
class StaticNode extends AstNodeNode, TStaticNode {
|
||||
override Static n;
|
||||
|
||||
StaticNode() { this = TStaticNode(n) }
|
||||
|
||||
Static getStatic() { result = n }
|
||||
}
|
||||
|
||||
cached
|
||||
newtype TNode =
|
||||
TExprNode(Expr e) { e.hasEnclosingCfgScope() and Stages::DataFlowStage::ref() } or
|
||||
@@ -755,4 +766,5 @@ newtype TNode =
|
||||
)
|
||||
} or
|
||||
TClosureSelfReferenceNode(CfgScope c) { lambdaCreationExpr(c) } or
|
||||
TCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn)
|
||||
TCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn) or
|
||||
TStaticNode(Static s)
|
||||
|
||||
2
rust/ql/lib/codeql/rust/elements/Impl.qll
generated
2
rust/ql/lib/codeql/rust/elements/Impl.qll
generated
@@ -13,7 +13,7 @@ import codeql.rust.elements.Visibility
|
||||
import codeql.rust.elements.WhereClause
|
||||
|
||||
/**
|
||||
* An `impl`` block.
|
||||
* An `impl` block.
|
||||
*
|
||||
* For example:
|
||||
* ```rust
|
||||
|
||||
11
rust/ql/lib/codeql/rust/elements/StaticAccess.qll
Normal file
11
rust/ql/lib/codeql/rust/elements/StaticAccess.qll
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* This module provides the public class `StaticAccess`.
|
||||
*/
|
||||
|
||||
private import internal.StaticImpl
|
||||
|
||||
final class StaticAccess = Impl::StaticAccess;
|
||||
|
||||
final class StaticWriteAccess = Impl::StaticWriteAccess;
|
||||
|
||||
final class StaticReadAccess = Impl::StaticReadAccess;
|
||||
@@ -48,15 +48,29 @@ module Impl {
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate isConstOrStatic(File f) {
|
||||
f = this.getFile() and
|
||||
(
|
||||
this instanceof Const
|
||||
or
|
||||
this instanceof Static
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the CFG scope that encloses this node, if any. */
|
||||
cached
|
||||
CfgScope getEnclosingCfgScope() {
|
||||
exists(AstNode p | p = this.getParentNode() |
|
||||
result = p
|
||||
result = p and
|
||||
not result instanceof SourceFile
|
||||
or
|
||||
not p instanceof CfgScope and
|
||||
not this.isConstOrStatic(_) and
|
||||
result = p.getEnclosingCfgScope()
|
||||
)
|
||||
or
|
||||
this.isConstOrStatic(result.(SourceFile).getFile())
|
||||
}
|
||||
|
||||
/** Holds if this node is inside a CFG scope. */
|
||||
|
||||
@@ -24,7 +24,12 @@ module Impl {
|
||||
* const X: i32 = 42;
|
||||
* ```
|
||||
*/
|
||||
class Const extends Generated::Const { }
|
||||
class Const extends Generated::Const {
|
||||
/** Gets an access to this constant item. */
|
||||
ConstAccess getAnAccess() { this = result.getConst() }
|
||||
|
||||
override string toStringImpl() { result = "const " + this.getName().getText() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A constant access.
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
* INTERNAL: Do not use.
|
||||
*/
|
||||
|
||||
private import rust
|
||||
private import codeql.rust.elements.internal.generated.Impl
|
||||
private import codeql.rust.internal.PathResolution as PathResolution
|
||||
private import codeql.rust.internal.typeinference.Type
|
||||
private import codeql.rust.internal.typeinference.TypeMention
|
||||
|
||||
/**
|
||||
* INTERNAL: This module contains the customizable definition of `Impl` and should not
|
||||
@@ -13,7 +17,7 @@ private import codeql.rust.elements.internal.generated.Impl
|
||||
module Impl {
|
||||
// the following QLdoc is generated: if you need to edit it, do it in the schema file
|
||||
/**
|
||||
* An `impl`` block.
|
||||
* An `impl` block.
|
||||
*
|
||||
* For example:
|
||||
* ```rust
|
||||
@@ -26,9 +30,9 @@ module Impl {
|
||||
override string toStringImpl() {
|
||||
exists(string trait |
|
||||
(
|
||||
trait = this.getTrait().toAbbreviatedString() + " for "
|
||||
trait = this.getTraitTy().toAbbreviatedString() + " for "
|
||||
or
|
||||
not this.hasTrait() and trait = ""
|
||||
not this.hasTraitTy() and trait = ""
|
||||
) and
|
||||
result = "impl " + trait + this.getSelfTy().toAbbreviatedString() + " { ... }"
|
||||
)
|
||||
@@ -38,6 +42,40 @@ module Impl {
|
||||
* Holds if this is an inherent `impl` block, that is, one that does not implement a trait.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
predicate isInherent() { not this.hasTrait() }
|
||||
predicate isInherent() { not this.hasTraitTy() }
|
||||
|
||||
/**
|
||||
* Gets the type being implemented.
|
||||
*
|
||||
* For example, in
|
||||
*
|
||||
* ```rust
|
||||
* impl MyType { ... }
|
||||
*
|
||||
* impl MyTrait for MyType { ... }
|
||||
* ```
|
||||
*
|
||||
* the type being implemented is in both cases `MyType`.
|
||||
*/
|
||||
TypeItem getSelf() {
|
||||
result = this.getSelfTy().(TypeMention).getType().(DataType).getTypeItem()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the trait being implemented, if any.
|
||||
*
|
||||
* For example, in
|
||||
*
|
||||
* ```rust
|
||||
* impl MyType { ... }
|
||||
*
|
||||
* impl MyTrait for MyType { ... }
|
||||
* ```
|
||||
*
|
||||
* the trait being implemented is in the second case `MyTrait`.
|
||||
*/
|
||||
Trait getTrait() {
|
||||
result = PathResolution::resolvePath(this.getTraitTy().(PathTypeRepr).getPath())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// generated by codegen, remove this comment if you wish to edit this file
|
||||
/**
|
||||
* This module provides a hand-modifiable wrapper around the generated class `Static`.
|
||||
*
|
||||
@@ -6,12 +5,17 @@
|
||||
*/
|
||||
|
||||
private import codeql.rust.elements.internal.generated.Static
|
||||
private import codeql.rust.elements.internal.AstNodeImpl::Impl as AstNodeImpl
|
||||
private import codeql.rust.elements.internal.PathExprImpl::Impl as PathExprImpl
|
||||
private import codeql.rust.elements.internal.VariableImpl::Impl as VariableImpl
|
||||
private import codeql.rust.internal.PathResolution
|
||||
|
||||
/**
|
||||
* INTERNAL: This module contains the customizable definition of `Static` and should not
|
||||
* be referenced directly.
|
||||
*/
|
||||
module Impl {
|
||||
// the following QLdoc is generated: if you need to edit it, do it in the schema file
|
||||
/**
|
||||
* A static item declaration.
|
||||
*
|
||||
@@ -20,5 +24,43 @@ module Impl {
|
||||
* static X: i32 = 42;
|
||||
* ```
|
||||
*/
|
||||
class Static extends Generated::Static { }
|
||||
class Static extends Generated::Static {
|
||||
/** Gets an access to this static item. */
|
||||
StaticAccess getAnAccess() { this = result.getStatic() }
|
||||
|
||||
override string toStringImpl() { result = "static " + this.getName().getText() }
|
||||
}
|
||||
|
||||
/**
|
||||
* A static access.
|
||||
*
|
||||
* For example:
|
||||
* ```rust
|
||||
* static X: i32 = 42;
|
||||
*
|
||||
* fn main() {
|
||||
* println!("{}", X);
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
class StaticAccess extends AstNodeImpl::AstNode, PathExprImpl::PathExpr {
|
||||
private Static s;
|
||||
|
||||
StaticAccess() { s = resolvePath(this.getPath()) }
|
||||
|
||||
/** Gets the static being accessed. */
|
||||
Static getStatic() { result = s }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "StaticAccess" }
|
||||
}
|
||||
|
||||
/** A static write access. */
|
||||
class StaticWriteAccess extends StaticAccess {
|
||||
StaticWriteAccess() { VariableImpl::assignmentOperationDescendant(_, this) }
|
||||
}
|
||||
|
||||
/** A static read access. */
|
||||
class StaticReadAccess extends StaticAccess {
|
||||
StaticReadAccess() { not this instanceof StaticWriteAccess }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import codeql.rust.elements.WhereClause
|
||||
*/
|
||||
module Generated {
|
||||
/**
|
||||
* An `impl`` block.
|
||||
* An `impl` block.
|
||||
*
|
||||
* For example:
|
||||
* ```rust
|
||||
@@ -109,16 +109,16 @@ module Generated {
|
||||
final predicate hasSelfTy() { exists(this.getSelfTy()) }
|
||||
|
||||
/**
|
||||
* Gets the trait of this impl, if it exists.
|
||||
* Gets the trait ty of this impl, if it exists.
|
||||
*/
|
||||
TypeRepr getTrait() {
|
||||
result = Synth::convertTypeReprFromRaw(Synth::convertImplToRaw(this).(Raw::Impl).getTrait())
|
||||
TypeRepr getTraitTy() {
|
||||
result = Synth::convertTypeReprFromRaw(Synth::convertImplToRaw(this).(Raw::Impl).getTraitTy())
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getTrait()` exists.
|
||||
* Holds if `getTraitTy()` exists.
|
||||
*/
|
||||
final predicate hasTrait() { exists(this.getTrait()) }
|
||||
final predicate hasTraitTy() { exists(this.getTraitTy()) }
|
||||
|
||||
/**
|
||||
* Gets the visibility of this impl, if it exists.
|
||||
|
||||
@@ -2328,7 +2328,7 @@ private module Impl {
|
||||
private Element getImmediateChildOfImpl(Impl e, int index, string partialPredicateCall) {
|
||||
exists(
|
||||
int n, int nAttributeMacroExpansion, int nAssocItemList, int nAttr, int nGenericParamList,
|
||||
int nSelfTy, int nTrait, int nVisibility, int nWhereClause
|
||||
int nSelfTy, int nTraitTy, int nVisibility, int nWhereClause
|
||||
|
|
||||
n = 0 and
|
||||
nAttributeMacroExpansion = n + 1 and
|
||||
@@ -2336,8 +2336,8 @@ private module Impl {
|
||||
nAttr = nAssocItemList + e.getNumberOfAttrs() and
|
||||
nGenericParamList = nAttr + 1 and
|
||||
nSelfTy = nGenericParamList + 1 and
|
||||
nTrait = nSelfTy + 1 and
|
||||
nVisibility = nTrait + 1 and
|
||||
nTraitTy = nSelfTy + 1 and
|
||||
nVisibility = nTraitTy + 1 and
|
||||
nWhereClause = nVisibility + 1 and
|
||||
(
|
||||
none()
|
||||
@@ -2359,9 +2359,9 @@ private module Impl {
|
||||
or
|
||||
index = nGenericParamList and result = e.getSelfTy() and partialPredicateCall = "SelfTy()"
|
||||
or
|
||||
index = nSelfTy and result = e.getTrait() and partialPredicateCall = "Trait()"
|
||||
index = nSelfTy and result = e.getTraitTy() and partialPredicateCall = "TraitTy()"
|
||||
or
|
||||
index = nTrait and result = e.getVisibility() and partialPredicateCall = "Visibility()"
|
||||
index = nTraitTy and result = e.getVisibility() and partialPredicateCall = "Visibility()"
|
||||
or
|
||||
index = nVisibility and
|
||||
result = e.getWhereClause() and
|
||||
|
||||
@@ -6209,7 +6209,7 @@ module Raw {
|
||||
|
||||
/**
|
||||
* INTERNAL: Do not use.
|
||||
* An `impl`` block.
|
||||
* An `impl` block.
|
||||
*
|
||||
* For example:
|
||||
* ```rust
|
||||
@@ -6262,9 +6262,9 @@ module Raw {
|
||||
TypeRepr getSelfTy() { impl_self_ties(this, result) }
|
||||
|
||||
/**
|
||||
* Gets the trait of this impl, if it exists.
|
||||
* Gets the trait ty of this impl, if it exists.
|
||||
*/
|
||||
TypeRepr getTrait() { impl_traits(this, result) }
|
||||
TypeRepr getTraitTy() { impl_trait_ties(this, result) }
|
||||
|
||||
/**
|
||||
* Gets the visibility of this impl, if it exists.
|
||||
@@ -6280,7 +6280,7 @@ module Raw {
|
||||
private Element getImmediateChildOfImpl(Impl e, int index) {
|
||||
exists(
|
||||
int n, int nAttributeMacroExpansion, int nAssocItemList, int nAttr, int nGenericParamList,
|
||||
int nSelfTy, int nTrait, int nVisibility, int nWhereClause
|
||||
int nSelfTy, int nTraitTy, int nVisibility, int nWhereClause
|
||||
|
|
||||
n = 0 and
|
||||
nAttributeMacroExpansion = n + 1 and
|
||||
@@ -6288,8 +6288,8 @@ module Raw {
|
||||
nAttr = nAssocItemList + e.getNumberOfAttrs() and
|
||||
nGenericParamList = nAttr + 1 and
|
||||
nSelfTy = nGenericParamList + 1 and
|
||||
nTrait = nSelfTy + 1 and
|
||||
nVisibility = nTrait + 1 and
|
||||
nTraitTy = nSelfTy + 1 and
|
||||
nVisibility = nTraitTy + 1 and
|
||||
nWhereClause = nVisibility + 1 and
|
||||
(
|
||||
none()
|
||||
@@ -6304,9 +6304,9 @@ module Raw {
|
||||
or
|
||||
index = nGenericParamList and result = e.getSelfTy()
|
||||
or
|
||||
index = nSelfTy and result = e.getTrait()
|
||||
index = nSelfTy and result = e.getTraitTy()
|
||||
or
|
||||
index = nTrait and result = e.getVisibility()
|
||||
index = nTraitTy and result = e.getVisibility()
|
||||
or
|
||||
index = nVisibility and result = e.getWhereClause()
|
||||
)
|
||||
|
||||
@@ -659,6 +659,38 @@ private class ConstItemNode extends AssocItemNode instanceof Const {
|
||||
override TypeParam getTypeParam(int i) { none() }
|
||||
}
|
||||
|
||||
private class StaticItemNode extends ItemNode instanceof Static {
|
||||
override string getName() { result = Static.super.getName().getText() }
|
||||
|
||||
override Namespace getNamespace() { result.isValue() }
|
||||
|
||||
override Visibility getVisibility() { result = Static.super.getVisibility() }
|
||||
|
||||
override Attr getAnAttr() { result = Static.super.getAnAttr() }
|
||||
|
||||
override TypeParam getTypeParam(int i) { none() }
|
||||
|
||||
override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) }
|
||||
|
||||
bindingset[c]
|
||||
private string getCanonicalPathPart(Crate c, int i) {
|
||||
i = 0 and
|
||||
result = this.getCanonicalPathPrefix(c)
|
||||
or
|
||||
i = 1 and
|
||||
result = "::"
|
||||
or
|
||||
i = 2 and
|
||||
result = this.getName()
|
||||
}
|
||||
|
||||
language[monotonicAggregates]
|
||||
override string getCanonicalPath(Crate c) {
|
||||
this.hasCanonicalPath(c) and
|
||||
result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i)
|
||||
}
|
||||
}
|
||||
|
||||
private class TypeItemTypeItemNode extends NamedItemNode, TypeItemNode instanceof TypeItem {
|
||||
override string getName() { result = TypeItem.super.getName().getText() }
|
||||
|
||||
@@ -806,7 +838,7 @@ private TypeItemNode resolveBuiltin(TypeRepr tr) {
|
||||
final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
|
||||
Path getSelfPath() { result = super.getSelfTy().(PathTypeRepr).getPath() }
|
||||
|
||||
Path getTraitPath() { result = super.getTrait().(PathTypeRepr).getPath() }
|
||||
Path getTraitPath() { result = super.getTraitTy().(PathTypeRepr).getPath() }
|
||||
|
||||
TypeItemNode resolveSelfTyBuiltin() { result = resolveBuiltin(this.(Impl).getSelfTy()) }
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ private predicate hasFirstNonTrivialTraitBound(TypeParamItemNode tp, Path traitB
|
||||
*/
|
||||
pragma[nomagic]
|
||||
predicate isBlanketLike(ImplItemNode i, TypePath blanketSelfPath, TypeParam blanketTypeParam) {
|
||||
i.(Impl).hasTrait() and
|
||||
i.(Impl).hasTraitTy() and
|
||||
(
|
||||
blanketTypeParam = i.getBlanketImplementationTypeParam() and
|
||||
blanketSelfPath.isEmpty()
|
||||
|
||||
@@ -174,7 +174,7 @@ private module Input2Common {
|
||||
exists(Impl impl |
|
||||
abs = impl and
|
||||
condition = impl.getSelfTy() and
|
||||
constraint = impl.getTrait()
|
||||
constraint = impl.getTraitTy()
|
||||
)
|
||||
or
|
||||
transitive = true and
|
||||
@@ -1542,7 +1542,7 @@ private module AssocFunctionResolution {
|
||||
boolean hasReceiver
|
||||
|
|
||||
afc.hasSyntacticInfo(name, arity, typeQualifier, traitQualifier, hasReceiver) and
|
||||
if not afc.hasATrait() and i.(Impl).hasTrait()
|
||||
if not afc.hasATrait() and i.(Impl).hasTraitTy()
|
||||
then callVisibleImplTraitCandidate(afc, i)
|
||||
else any()
|
||||
|
|
||||
@@ -2532,7 +2532,7 @@ private module AssocFunctionResolution {
|
||||
AssocFunctionCallCand afcc, TypeAbstraction abs, AssocFunctionType constraint
|
||||
) {
|
||||
potentialInstantiationOf0(afcc, abs, constraint) and
|
||||
if abs.(Impl).hasTrait()
|
||||
if abs.(Impl).hasTraitTy()
|
||||
then
|
||||
// inherent functions take precedence over trait functions, so only allow
|
||||
// trait functions when there are no matching inherent functions
|
||||
@@ -2584,7 +2584,7 @@ private module AssocFunctionResolution {
|
||||
exists(AssocFunctionCall afc, FunctionPosition selfPos |
|
||||
afcc = MkAssocFunctionCallCand(afc, selfPos, _, _) and
|
||||
blanketLikeCandidate(afc, _, selfPos, abs, constraint, _, _) and
|
||||
if abs.(Impl).hasTrait()
|
||||
if abs.(Impl).hasTraitTy()
|
||||
then
|
||||
// inherent functions take precedence over trait functions, so only allow
|
||||
// trait functions when there are no matching inherent functions
|
||||
|
||||
@@ -2907,9 +2907,9 @@ impl_self_ties(
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
impl_traits(
|
||||
impl_trait_ties(
|
||||
int id: @impl ref,
|
||||
int trait: @type_repr ref
|
||||
int trait_ty: @type_repr ref
|
||||
);
|
||||
|
||||
#keyset[id]
|
||||
|
||||
@@ -11,6 +11,7 @@ import codeql.rust.elements.AssignmentOperation
|
||||
import codeql.rust.elements.BitwiseOperation
|
||||
import codeql.rust.elements.ComparisonOperation
|
||||
import codeql.rust.elements.ConstAccess
|
||||
import codeql.rust.elements.StaticAccess
|
||||
import codeql.rust.elements.DerefExpr
|
||||
import codeql.rust.elements.LiteralExprExt
|
||||
import codeql.rust.elements.LogicalOperation
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
description: Renamed `impl_traits` to `impl_trait_ties`
|
||||
compatibility: full
|
||||
|
||||
impl_trait_ties.rel: reorder impl_traits(@impl id, @type_repr trait) id trait
|
||||
impl_traits.rel: delete
|
||||
@@ -14,7 +14,7 @@ private module ResolveTest implements TestSig {
|
||||
i.getLocation().hasLocationInfo(filepath, _, _, line, _)
|
||||
}
|
||||
|
||||
private predicate commmentAt(string text, string filepath, int line) {
|
||||
private predicate commentAt(string text, string filepath, int line) {
|
||||
exists(Comment c |
|
||||
c.getLocation().hasLocationInfo(filepath, line, _, _, _) and
|
||||
c.getCommentText().trim() = text and
|
||||
@@ -28,9 +28,9 @@ private module ResolveTest implements TestSig {
|
||||
if i instanceof SourceFile
|
||||
then value = i.getFile().getBaseName()
|
||||
else (
|
||||
commmentAt(value, filepath, line)
|
||||
commentAt(value, filepath, line)
|
||||
or
|
||||
not commmentAt(_, filepath, line) and
|
||||
not commentAt(_, filepath, line) and
|
||||
value = i.getName()
|
||||
)
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ private newtype TCallable =
|
||||
or
|
||||
// If a method implements a public trait it is exposed through the trait.
|
||||
// We overapproximate this by including all trait method implementations.
|
||||
exists(R::Impl impl | impl.hasTrait() and impl.getAssocItemList().getAssocItem(_) = api)
|
||||
exists(R::Impl impl | impl.hasTraitTy() and impl.getAssocItemList().getAssocItem(_) = api)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,3 +20,12 @@ class CrateElement extends Element {
|
||||
class Builtin extends AstNode {
|
||||
Builtin() { this.getFile().getAbsolutePath().matches("%/builtins/%.rs") }
|
||||
}
|
||||
|
||||
predicate commentAt(string text, string filepath, int line) {
|
||||
exists(Comment c |
|
||||
c.getLocation().hasLocationInfo(filepath, line, _, _, _) and
|
||||
c.getCommentText().trim() = text and
|
||||
c.fromSource() and
|
||||
not text.matches("$%")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ query predicate canonicalPath(Addressable a, string path) {
|
||||
a =
|
||||
any(ImplItemNode i |
|
||||
i.resolveSelfTy() instanceof Str and
|
||||
not i.(Impl).hasTrait()
|
||||
not i.(Impl).hasTraitTy()
|
||||
).getAnAssocItem() and
|
||||
a.(Function).getName().getText() = "trim"
|
||||
) and
|
||||
|
||||
@@ -52,7 +52,7 @@ GenericArgList/gen_generic_arg_list.rs cfb072d3b48f9dd568c23d4dfefba28766628678f
|
||||
GenericParamList/gen_generic_param_list.rs 3a1981a7c4731329ad6da0d887f09be04f31342d94f44711ac0ac455930f773a 3a1981a7c4731329ad6da0d887f09be04f31342d94f44711ac0ac455930f773a
|
||||
IdentPat/gen_ident_pat.rs 87f9201ca47683ff6f12a0c844c062fdedb6d86546794522d358b117ba0fe477 87f9201ca47683ff6f12a0c844c062fdedb6d86546794522d358b117ba0fe477
|
||||
IfExpr/gen_if_expr.rs 2df66735394ebb20db29d3fbf2721ad4812afbe8d4614d03f26265c1f481f1e8 2df66735394ebb20db29d3fbf2721ad4812afbe8d4614d03f26265c1f481f1e8
|
||||
Impl/gen_impl.rs cfab33eb5e98b425b1d88be5f09f742be6c4f8d402e1becd4421aabb0431aadd cfab33eb5e98b425b1d88be5f09f742be6c4f8d402e1becd4421aabb0431aadd
|
||||
Impl/gen_impl.rs a3f91dbcbb89f660e1c67eb6211def495cced5ab069515c6151e442365f64899 a3f91dbcbb89f660e1c67eb6211def495cced5ab069515c6151e442365f64899
|
||||
ImplTraitTypeRepr/gen_impl_trait_type_repr.rs ebfa4d350ae5759bf7df6adf790d2d892c7a0d708f3340ccf3e12a681cb78f00 ebfa4d350ae5759bf7df6adf790d2d892c7a0d708f3340ccf3e12a681cb78f00
|
||||
IndexExpr/gen_index_expr.rs 22d7f81ba43dc63f1f49e21a2c25ce25a1b8f6e8e95e1a66f518f010a4d73c61 22d7f81ba43dc63f1f49e21a2c25ce25a1b8f6e8e95e1a66f518f010a4d73c61
|
||||
InferTypeRepr/gen_infer_type_repr.rs cd50eaeffdf16e0e896b14b665590251a4d383c123502ed667d8b1f75000f559 cd50eaeffdf16e0e896b14b665590251a4d383c123502ed667d8b1f75000f559
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
instances
|
||||
| gen_const.rs:4:5:7:22 | Const | isConst: | yes | isDefault: | no | hasImplementation: | yes |
|
||||
| gen_const.rs:4:5:7:22 | const X | isConst: | yes | isDefault: | no | hasImplementation: | yes |
|
||||
getAttributeMacroExpansion
|
||||
getAttr
|
||||
getBody
|
||||
| gen_const.rs:4:5:7:22 | Const | gen_const.rs:7:20:7:21 | 42 |
|
||||
| gen_const.rs:4:5:7:22 | const X | gen_const.rs:7:20:7:21 | 42 |
|
||||
getGenericParamList
|
||||
getName
|
||||
| gen_const.rs:4:5:7:22 | Const | gen_const.rs:7:11:7:11 | X |
|
||||
| gen_const.rs:4:5:7:22 | const X | gen_const.rs:7:11:7:11 | X |
|
||||
getTypeRepr
|
||||
| gen_const.rs:4:5:7:22 | Const | gen_const.rs:7:14:7:16 | i32 |
|
||||
| gen_const.rs:4:5:7:22 | const X | gen_const.rs:7:14:7:16 | i32 |
|
||||
getVisibility
|
||||
getWhereClause
|
||||
|
||||
@@ -3,4 +3,4 @@ instances
|
||||
getAttr
|
||||
getExternItem
|
||||
| gen_extern_item_list.rs:7:16:10:5 | ExternItemList | 0 | gen_extern_item_list.rs:8:9:8:17 | fn foo |
|
||||
| gen_extern_item_list.rs:7:16:10:5 | ExternItemList | 1 | gen_extern_item_list.rs:9:9:9:24 | Static |
|
||||
| gen_extern_item_list.rs:7:16:10:5 | ExternItemList | 1 | gen_extern_item_list.rs:9:9:9:24 | static BAR |
|
||||
|
||||
@@ -7,7 +7,7 @@ getAttr
|
||||
getGenericParamList
|
||||
getSelfTy
|
||||
| gen_impl.rs:4:5:9:5 | impl MyTrait for MyType { ... } | gen_impl.rs:7:22:7:27 | MyType |
|
||||
getTrait
|
||||
getTraitTy
|
||||
| gen_impl.rs:4:5:9:5 | impl MyTrait for MyType { ... } | gen_impl.rs:7:10:7:16 | MyTrait |
|
||||
getVisibility
|
||||
getWhereClause
|
||||
|
||||
@@ -38,8 +38,8 @@ query predicate getSelfTy(Impl x, TypeRepr getSelfTy) {
|
||||
toBeTested(x) and not x.isUnknown() and getSelfTy = x.getSelfTy()
|
||||
}
|
||||
|
||||
query predicate getTrait(Impl x, TypeRepr getTrait) {
|
||||
toBeTested(x) and not x.isUnknown() and getTrait = x.getTrait()
|
||||
query predicate getTraitTy(Impl x, TypeRepr getTraitTy) {
|
||||
toBeTested(x) and not x.isUnknown() and getTraitTy = x.getTraitTy()
|
||||
}
|
||||
|
||||
query predicate getVisibility(Impl x, Visibility getVisibility) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// generated by codegen, do not edit
|
||||
|
||||
fn test_impl() -> () {
|
||||
// An `impl`` block.
|
||||
// An `impl` block.
|
||||
//
|
||||
// For example:
|
||||
impl MyTrait for MyType {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
instances
|
||||
| gen_static.rs:4:5:7:23 | Static | isMut: | no | isStatic: | yes | isUnsafe: | no |
|
||||
| gen_static.rs:4:5:7:23 | static X | isMut: | no | isStatic: | yes | isUnsafe: | no |
|
||||
getAttributeMacroExpansion
|
||||
getAttr
|
||||
getBody
|
||||
| gen_static.rs:4:5:7:23 | Static | gen_static.rs:7:21:7:22 | 42 |
|
||||
| gen_static.rs:4:5:7:23 | static X | gen_static.rs:7:21:7:22 | 42 |
|
||||
getName
|
||||
| gen_static.rs:4:5:7:23 | Static | gen_static.rs:7:12:7:12 | X |
|
||||
| gen_static.rs:4:5:7:23 | static X | gen_static.rs:7:12:7:12 | X |
|
||||
getTypeRepr
|
||||
| gen_static.rs:4:5:7:23 | Static | gen_static.rs:7:15:7:17 | i32 |
|
||||
| gen_static.rs:4:5:7:23 | static X | gen_static.rs:7:15:7:17 | i32 |
|
||||
getVisibility
|
||||
|
||||
@@ -797,7 +797,7 @@ macro_expansion.rs:
|
||||
# 84| getSegment(): [PathSegment] MyDerive::<...>
|
||||
# 83| getGenericArgList(): [GenericArgList] <...>
|
||||
# 84| getIdentifier(): [NameRef] MyDerive
|
||||
# 83| getTrait(): [PathTypeRepr] ...::Debug
|
||||
# 83| getTraitTy(): [PathTypeRepr] ...::Debug
|
||||
# 83| getPath(): [Path] ...::Debug
|
||||
# 83| getQualifier(): [Path] ...::fmt
|
||||
# 83| getQualifier(): [Path] $crate
|
||||
@@ -901,7 +901,7 @@ macro_expansion.rs:
|
||||
# 89| getSegment(): [PathSegment] MyDeriveEnum::<...>
|
||||
# 88| getGenericArgList(): [GenericArgList] <...>
|
||||
# 89| getIdentifier(): [NameRef] MyDeriveEnum
|
||||
# 88| getTrait(): [PathTypeRepr] ...::PartialEq
|
||||
# 88| getTraitTy(): [PathTypeRepr] ...::PartialEq
|
||||
# 88| getPath(): [Path] ...::PartialEq
|
||||
# 88| getQualifier(): [Path] ...::cmp
|
||||
# 88| getQualifier(): [Path] $crate
|
||||
@@ -921,7 +921,7 @@ macro_expansion.rs:
|
||||
# 89| getSegment(): [PathSegment] MyDeriveEnum::<...>
|
||||
# 88| getGenericArgList(): [GenericArgList] <...>
|
||||
# 89| getIdentifier(): [NameRef] MyDeriveEnum
|
||||
# 88| getTrait(): [PathTypeRepr] ...::Eq
|
||||
# 88| getTraitTy(): [PathTypeRepr] ...::Eq
|
||||
# 88| getPath(): [Path] ...::Eq
|
||||
# 88| getQualifier(): [Path] ...::cmp
|
||||
# 88| getQualifier(): [Path] $crate
|
||||
@@ -957,7 +957,7 @@ macro_expansion.rs:
|
||||
# 94| getName(): [Name] MyTrait
|
||||
# 98| getItem(20): [Union] union MyDeriveUnion
|
||||
# 99| getDeriveMacroExpansion(0): [MacroItems] MacroItems
|
||||
# 99| getItem(0): [Const] Const
|
||||
# 99| getItem(0): [Const] const CONST_MyDeriveUnion
|
||||
# 98| getBody(): [IntegerLiteralExpr] 42
|
||||
# 99| getName(): [Name] CONST_MyDeriveUnion
|
||||
# 98| getTypeRepr(): [PathTypeRepr] u32
|
||||
@@ -984,7 +984,7 @@ macro_expansion.rs:
|
||||
# 99| getPath(): [Path] MyDeriveUnion
|
||||
# 99| getSegment(): [PathSegment] MyDeriveUnion
|
||||
# 99| getIdentifier(): [NameRef] MyDeriveUnion
|
||||
# 98| getTrait(): [PathTypeRepr] MyTrait
|
||||
# 98| getTraitTy(): [PathTypeRepr] MyTrait
|
||||
# 98| getPath(): [Path] MyTrait
|
||||
# 98| getSegment(): [PathSegment] MyTrait
|
||||
# 98| getIdentifier(): [NameRef] MyTrait
|
||||
|
||||
@@ -18,7 +18,7 @@ derive_macros
|
||||
| macro_expansion.rs:83:1:86:1 | struct MyDerive | 0 | 0 | macro_expansion.rs:84:8:85:9 | impl ...::Debug for MyDerive::<...> { ... } |
|
||||
| macro_expansion.rs:88:1:92:1 | enum MyDeriveEnum | 0 | 0 | macro_expansion.rs:89:6:91:12 | impl ...::PartialEq for MyDeriveEnum::<...> { ... } |
|
||||
| macro_expansion.rs:88:1:92:1 | enum MyDeriveEnum | 1 | 0 | macro_expansion.rs:89:6:89:17 | impl ...::Eq for MyDeriveEnum::<...> { ... } |
|
||||
| macro_expansion.rs:98:1:102:1 | union MyDeriveUnion | 0 | 0 | macro_expansion.rs:99:7:99:19 | Const |
|
||||
| macro_expansion.rs:98:1:102:1 | union MyDeriveUnion | 0 | 0 | macro_expansion.rs:99:7:99:19 | const CONST_MyDeriveUnion |
|
||||
| macro_expansion.rs:98:1:102:1 | union MyDeriveUnion | 0 | 1 | macro_expansion.rs:99:7:99:19 | impl MyTrait for MyDeriveUnion { ... } |
|
||||
macro_calls
|
||||
| macro_expansion.rs:5:9:5:35 | concat!... | macro_expansion.rs:5:17:5:34 | "Hello world!" |
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
testFailures
|
||||
constAccess
|
||||
| main.rs:17:13:17:24 | GLOBAL_CONST | main.rs:1:1:1:29 | Const |
|
||||
| main.rs:19:13:19:24 | STRING_CONST | main.rs:2:1:2:35 | Const |
|
||||
| main.rs:21:13:21:33 | ...::ASSOC_CONST | main.rs:9:5:9:33 | Const |
|
||||
| main.rs:23:13:23:35 | ...::MODULE_CONST | main.rs:13:5:13:38 | Const |
|
||||
| main.rs:25:8:25:19 | GLOBAL_CONST | main.rs:1:1:1:29 | Const |
|
||||
| main.rs:29:16:29:36 | ...::ASSOC_CONST | main.rs:9:5:9:33 | Const |
|
||||
| main.rs:17:13:17:24 | GLOBAL_CONST | main.rs:1:1:1:29 | const GLOBAL_CONST |
|
||||
| main.rs:19:13:19:24 | STRING_CONST | main.rs:2:1:2:35 | const STRING_CONST |
|
||||
| main.rs:21:13:21:33 | ...::ASSOC_CONST | main.rs:9:5:9:33 | const ASSOC_CONST |
|
||||
| main.rs:23:13:23:35 | ...::MODULE_CONST | main.rs:13:5:13:38 | const MODULE_CONST |
|
||||
| main.rs:26:16:26:27 | GLOBAL_CONST | main.rs:1:1:1:29 | const GLOBAL_CONST |
|
||||
| main.rs:30:16:30:36 | ...::ASSOC_CONST | main.rs:9:5:9:33 | const ASSOC_CONST |
|
||||
| main.rs:33:20:33:31 | GLOBAL_CONST | main.rs:1:1:1:29 | const GLOBAL_CONST |
|
||||
| main.rs:39:17:39:28 | STRING_CONST | main.rs:38:9:38:43 | const STRING_CONST |
|
||||
| main.rs:43:21:43:32 | STRING_CONST | main.rs:42:13:42:48 | const STRING_CONST |
|
||||
|
||||
@@ -5,15 +5,25 @@ import TestUtils
|
||||
query predicate constAccess(ConstAccess ca, Const c) { toBeTested(ca) and c = ca.getConst() }
|
||||
|
||||
module ConstAccessTest implements TestSig {
|
||||
private predicate constAt(Const c, string filepath, int line) {
|
||||
c.getLocation().hasLocationInfo(filepath, _, _, line, _)
|
||||
}
|
||||
|
||||
string getARelevantTag() { result = "const_access" }
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(ConstAccess ca |
|
||||
exists(ConstAccess ca, Const c, string filepath, int line |
|
||||
toBeTested(ca) and
|
||||
location = ca.getLocation() and
|
||||
element = ca.toString() and
|
||||
tag = "const_access" and
|
||||
value = ca.getConst().getName().getText()
|
||||
c = ca.getConst() and
|
||||
constAt(c, filepath, line)
|
||||
|
|
||||
commentAt(value, filepath, line)
|
||||
or
|
||||
not commentAt(_, filepath, line) and
|
||||
value = c.getName().getText()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,18 +15,34 @@ mod my_module {
|
||||
|
||||
fn use_consts() {
|
||||
let x = GLOBAL_CONST; // $ const_access=GLOBAL_CONST
|
||||
|
||||
|
||||
let s = STRING_CONST; // $ const_access=STRING_CONST
|
||||
|
||||
|
||||
let y = MyStruct::ASSOC_CONST; // $ const_access=ASSOC_CONST
|
||||
|
||||
|
||||
let z = my_module::MODULE_CONST; // $ const_access=MODULE_CONST
|
||||
|
||||
if GLOBAL_CONST > 0 { // $ const_access=GLOBAL_CONST
|
||||
|
||||
#[rustfmt::skip]
|
||||
let _ = if GLOBAL_CONST > 0 { // $ const_access=GLOBAL_CONST
|
||||
println!("positive");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
let arr = [MyStruct::ASSOC_CONST; 5]; // $ const_access=ASSOC_CONST
|
||||
|
||||
#[rustfmt::skip]
|
||||
let _ = if let GLOBAL_CONST = 0 { // $ const_access=GLOBAL_CONST
|
||||
println!("zero");
|
||||
};
|
||||
|
||||
{
|
||||
const STRING_CONST: &str = "inner"; // Inner1
|
||||
let _ = STRING_CONST; // $ const_access=Inner1
|
||||
|
||||
{
|
||||
const STRING_CONST: &str = "inner2"; // Inner2
|
||||
let _ = STRING_CONST; // $ const_access=Inner2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -1317,10 +1317,9 @@ edges
|
||||
| test.rs:533:21:533:48 | { ... } | test.rs:533:21:533:48 | { ... } | |
|
||||
| test.rs:533:48:533:48 | 0 | test.rs:533:21:533:48 | ... > ... | |
|
||||
| test.rs:536:9:536:10 | 42 | test.rs:529:41:537:5 | { ... } | |
|
||||
| test.rs:539:5:548:5 | enter fn const_block_panic | test.rs:540:9:540:30 | Const | |
|
||||
| test.rs:539:5:548:5 | enter fn const_block_panic | test.rs:541:9:546:9 | ExprStmt | |
|
||||
| test.rs:539:5:548:5 | exit fn const_block_panic (normal) | test.rs:539:5:548:5 | exit fn const_block_panic | |
|
||||
| test.rs:539:35:548:5 | { ... } | test.rs:539:5:548:5 | exit fn const_block_panic (normal) | |
|
||||
| test.rs:540:9:540:30 | Const | test.rs:541:9:546:9 | ExprStmt | |
|
||||
| test.rs:541:9:546:9 | ExprStmt | test.rs:541:12:541:16 | false | |
|
||||
| test.rs:541:9:546:9 | if false {...} | test.rs:547:9:547:9 | N | |
|
||||
| test.rs:541:12:541:16 | false | test.rs:541:9:546:9 | if false {...} | false |
|
||||
|
||||
@@ -222,6 +222,15 @@ edges
|
||||
| main.rs:415:18:415:38 | i.get_double_number() | main.rs:415:13:415:14 | n4 | provenance | |
|
||||
| main.rs:418:13:418:14 | n5 | main.rs:419:14:419:15 | n5 | provenance | |
|
||||
| main.rs:418:18:418:41 | ...::get_default(...) | main.rs:418:13:418:14 | n5 | provenance | |
|
||||
| main.rs:426:30:426:39 | source(...) | main.rs:430:35:430:45 | CONST_VALUE | provenance | |
|
||||
| main.rs:427:5:427:46 | static STATIC_VALUE | main.rs:433:32:433:43 | STATIC_VALUE | provenance | |
|
||||
| main.rs:427:5:427:46 | static STATIC_VALUE | main.rs:437:18:437:29 | STATIC_VALUE | provenance | |
|
||||
| main.rs:427:36:427:45 | source(...) | main.rs:427:5:427:46 | static STATIC_VALUE | provenance | |
|
||||
| main.rs:430:35:430:45 | CONST_VALUE | main.rs:431:14:431:25 | CONST_VALUE2 | provenance | |
|
||||
| main.rs:433:17:433:28 | static_value | main.rs:434:18:434:29 | static_value | provenance | |
|
||||
| main.rs:433:32:433:43 | STATIC_VALUE | main.rs:433:17:433:28 | static_value | provenance | |
|
||||
| main.rs:436:13:436:24 | STATIC_VALUE | main.rs:427:5:427:46 | static STATIC_VALUE | provenance | |
|
||||
| main.rs:436:28:436:37 | source(...) | main.rs:436:13:436:24 | STATIC_VALUE | provenance | |
|
||||
nodes
|
||||
| main.rs:12:28:14:1 | { ... } | semmle.label | { ... } |
|
||||
| main.rs:13:5:13:13 | source(...) | semmle.label | source(...) |
|
||||
@@ -464,6 +473,17 @@ nodes
|
||||
| main.rs:418:13:418:14 | n5 | semmle.label | n5 |
|
||||
| main.rs:418:18:418:41 | ...::get_default(...) | semmle.label | ...::get_default(...) |
|
||||
| main.rs:419:14:419:15 | n5 | semmle.label | n5 |
|
||||
| main.rs:426:30:426:39 | source(...) | semmle.label | source(...) |
|
||||
| main.rs:427:5:427:46 | static STATIC_VALUE | semmle.label | static STATIC_VALUE |
|
||||
| main.rs:427:36:427:45 | source(...) | semmle.label | source(...) |
|
||||
| main.rs:430:35:430:45 | CONST_VALUE | semmle.label | CONST_VALUE |
|
||||
| main.rs:431:14:431:25 | CONST_VALUE2 | semmle.label | CONST_VALUE2 |
|
||||
| main.rs:433:17:433:28 | static_value | semmle.label | static_value |
|
||||
| main.rs:433:32:433:43 | STATIC_VALUE | semmle.label | STATIC_VALUE |
|
||||
| main.rs:434:18:434:29 | static_value | semmle.label | static_value |
|
||||
| main.rs:436:13:436:24 | STATIC_VALUE | semmle.label | STATIC_VALUE |
|
||||
| main.rs:436:28:436:37 | source(...) | semmle.label | source(...) |
|
||||
| main.rs:437:18:437:29 | STATIC_VALUE | semmle.label | STATIC_VALUE |
|
||||
subpaths
|
||||
| main.rs:38:16:38:24 | source(...) | main.rs:26:28:26:33 | ...: i64 | main.rs:26:17:26:25 | SelfParam [Return] [&ref, MyStruct] | main.rs:38:5:38:5 | [post] a [MyStruct] |
|
||||
| main.rs:39:10:39:10 | a [MyStruct] | main.rs:30:17:30:21 | SelfParam [&ref, MyStruct] | main.rs:30:31:32:5 | { ... } | main.rs:39:10:39:21 | a.get_data() |
|
||||
@@ -525,3 +545,8 @@ testFailures
|
||||
| main.rs:412:14:412:15 | n3 | main.rs:371:13:371:21 | source(...) | main.rs:412:14:412:15 | n3 | $@ | main.rs:371:13:371:21 | source(...) | source(...) |
|
||||
| main.rs:416:14:416:15 | n4 | main.rs:391:13:391:22 | source(...) | main.rs:416:14:416:15 | n4 | $@ | main.rs:391:13:391:22 | source(...) | source(...) |
|
||||
| main.rs:419:14:419:15 | n5 | main.rs:395:13:395:21 | source(...) | main.rs:419:14:419:15 | n5 | $@ | main.rs:395:13:395:21 | source(...) | source(...) |
|
||||
| main.rs:431:14:431:25 | CONST_VALUE2 | main.rs:426:30:426:39 | source(...) | main.rs:431:14:431:25 | CONST_VALUE2 | $@ | main.rs:426:30:426:39 | source(...) | source(...) |
|
||||
| main.rs:434:18:434:29 | static_value | main.rs:427:36:427:45 | source(...) | main.rs:434:18:434:29 | static_value | $@ | main.rs:427:36:427:45 | source(...) | source(...) |
|
||||
| main.rs:434:18:434:29 | static_value | main.rs:436:28:436:37 | source(...) | main.rs:434:18:434:29 | static_value | $@ | main.rs:436:28:436:37 | source(...) | source(...) |
|
||||
| main.rs:437:18:437:29 | STATIC_VALUE | main.rs:427:36:427:45 | source(...) | main.rs:437:18:437:29 | STATIC_VALUE | $@ | main.rs:427:36:427:45 | source(...) | source(...) |
|
||||
| main.rs:437:18:437:29 | STATIC_VALUE | main.rs:436:28:436:37 | source(...) | main.rs:437:18:437:29 | STATIC_VALUE | $@ | main.rs:436:28:436:37 | source(...) | source(...) |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fn source(i: i64) -> i64 {
|
||||
const fn source(i: i64) -> i64 {
|
||||
1000 + i
|
||||
}
|
||||
|
||||
@@ -420,6 +420,25 @@ mod not_trait_dispatch {
|
||||
}
|
||||
}
|
||||
|
||||
mod const_static {
|
||||
use super::{sink, source};
|
||||
|
||||
const CONST_VALUE: i64 = source(42);
|
||||
static mut STATIC_VALUE: i64 = source(43);
|
||||
|
||||
fn test_const_static() {
|
||||
const CONST_VALUE2: i64 = CONST_VALUE;
|
||||
sink(CONST_VALUE2); // $ hasValueFlow=42
|
||||
unsafe {
|
||||
let static_value = STATIC_VALUE;
|
||||
sink(static_value); // $ hasValueFlow=43 $ SPURIOUS: hasValueFlow=44 (statics are not control-flow sensitive)
|
||||
|
||||
STATIC_VALUE = source(44);
|
||||
sink(STATIC_VALUE); // $ hasValueFlow=44 $ SPURIOUS: hasValueFlow=43 (statics are not control-flow sensitive)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
data_out_of_call();
|
||||
data_out_of_call_side_effect1();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user