Skip to content

Commit 3051903

Browse files
authored
Merge branch 'github:main' into main
2 parents 5ab068a + b9f1cc5 commit 3051903

File tree

244 files changed

+4091
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+4091
-219
lines changed

.github/workflows/swift-qltest.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ jobs:
2323
- uses: ./.github/actions/fetch-codeql
2424
- name: Check QL formatting
2525
run: find ql "(" -name "*.ql" -or -name "*.qll" ")" -print0 | xargs -0 codeql query format --check-only
26+
qltest-test:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
- uses: bazelbuild/setup-bazelisk@v2
31+
- uses: actions/setup-python@v4
32+
with:
33+
python-version-file: 'swift/.python-version'
34+
- name: Test qltest.sh
35+
run: |
36+
bazel test //swift/tools/test/qltest
2637
qltest:
2738
runs-on: ${{ matrix.os }}
2839
strategy:
2940
fail-fast: false
3041
matrix:
31-
os : [ubuntu-20.04, macos-latest]
42+
os: [ ubuntu-20.04, macos-latest ]
3243
steps:
3344
- uses: actions/checkout@v3
3445
- uses: ./.github/actions/fetch-codeql

cpp/ql/test/library-tests/templates/CPP-223/decls.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| test.cpp:4:26:4:26 | c<<expression>> |
1414
| test.cpp:4:26:4:26 | c<<unnamed>> |
1515
| test.cpp:5:29:5:29 | e |
16+
| test.cpp:6:24:6:24 | f |
1617
| test.cpp:6:26:6:26 | (unnamed parameter 0) |
1718
| test.cpp:6:29:6:31 | (unnamed parameter 1) |
1819
| test.cpp:7:20:7:20 | f |

docs/codeql/ql-language-reference/signatures.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ Type signatures
4040
===============
4141

4242
Type signatures declare module parameters that will be substituted with types when the module is instantiated.
43-
Type signatures are used to specify supertypes and are the simplest category of signatures.
43+
Type signatures may specify supertypes and required member predicates (in addition to those member predicates that are
44+
implied by the supertypes).
4445

4546
The substitution of type signatures relies on structural typing. That is, types do not have to be explicitly defined as
46-
implementing a type signature - they just need to have the specified (transitive) supertypes.
47+
implementing a type signature - they just need to have the specified (transitive) supertypes and member predicates.
4748

4849
In detail, a type signature definition consists of:
4950

@@ -52,14 +53,19 @@ In detail, a type signature definition consists of:
5253
#. The name of the type signature. This is an `identifier <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#identifiers>`_
5354
starting with a uppercase letter.
5455
#. Optionally, the keyword ``extends`` followed by a list of types, separated by commas.
55-
#. A semicolon ``;``.
56+
#. Either a semicolon ``;`` or a list of predicate signatures enclosed in braces.
57+
The ``signature`` keyword is omitted for these contained signatures.
5658

5759
For example:
5860

5961
.. code-block:: ql
6062
6163
signature class ExtendsInt extends int;
6264
65+
signature class CanBePrinted {
66+
string toString();
67+
}
68+
6369
Module signatures
6470
=================
6571

java/kotlin-extractor/src/main/kotlin/ExternalDeclExtractor.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class ExternalDeclExtractor(val logger: FileLogger, val invocationTrapFile: Stri
3535
if (ret) externalDeclWorkList.add(Pair(d, signature))
3636
return ret
3737
}
38-
fun extractLater(p: IrProperty) = extractLater(p, propertySignature)
39-
fun extractLater(f: IrField) = extractLater(f, fieldSignature)
4038
fun extractLater(c: IrClass) = extractLater(c, "")
4139

4240
fun extractExternalClasses() {

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.codeql
22

33
import com.github.codeql.utils.*
44
import com.github.codeql.utils.versions.codeQlWithHasQuestionMark
5+
import com.github.codeql.utils.versions.getKotlinType
56
import com.github.codeql.utils.versions.isRawType
67
import com.semmle.extractor.java.OdasaOutput
78
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
@@ -22,6 +23,7 @@ import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature
2223
import org.jetbrains.kotlin.load.java.JvmAbi
2324
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
2425
import org.jetbrains.kotlin.load.java.structure.*
26+
import org.jetbrains.kotlin.load.java.typeEnhancement.hasEnhancedNullability
2527
import org.jetbrains.kotlin.load.kotlin.getJvmModuleNameForDeserializedDescriptor
2628
import org.jetbrains.kotlin.name.FqName
2729
import org.jetbrains.kotlin.name.NameUtils
@@ -253,19 +255,24 @@ open class KotlinUsesExtractor(
253255
}
254256
}
255257

258+
private fun propertySignature(p: IrProperty) =
259+
((p.getter ?: p.setter)?.extensionReceiverParameter?.let { useType(erase(it.type)).javaResult.signature } ?: "")
260+
256261
private fun extractPropertyLaterIfExternalFileMember(p: IrProperty) {
257262
if (isExternalFileClassMember(p)) {
258263
extractExternalClassLater(p.parentAsClass)
259-
dependencyCollector?.addDependency(p, externalClassExtractor.propertySignature)
260-
externalClassExtractor.extractLater(p)
264+
val signature = propertySignature(p) + externalClassExtractor.propertySignature
265+
dependencyCollector?.addDependency(p, signature)
266+
externalClassExtractor.extractLater(p, signature)
261267
}
262268
}
263269

264270
private fun extractFieldLaterIfExternalFileMember(f: IrField) {
265271
if (isExternalFileClassMember(f)) {
266272
extractExternalClassLater(f.parentAsClass)
267-
dependencyCollector?.addDependency(f, externalClassExtractor.fieldSignature)
268-
externalClassExtractor.extractLater(f)
273+
val signature = (f.correspondingPropertySymbol?.let { propertySignature(it.owner) } ?: "") + externalClassExtractor.fieldSignature
274+
dependencyCollector?.addDependency(f, signature)
275+
externalClassExtractor.extractLater(f, signature)
269276
}
270277
}
271278

@@ -669,7 +676,8 @@ open class KotlinUsesExtractor(
669676
otherIsPrimitive: Boolean,
670677
javaClass: IrClass,
671678
kotlinPackageName: String, kotlinClassName: String): TypeResults {
672-
val javaResult = if ((context == TypeContext.RETURN || (context == TypeContext.OTHER && otherIsPrimitive)) && !s.isNullable() && primitiveName != null) {
679+
// Note the use of `hasEnhancedNullability` here covers cases like `@NotNull Integer`, which must be extracted as `Integer` not `int`.
680+
val javaResult = if ((context == TypeContext.RETURN || (context == TypeContext.OTHER && otherIsPrimitive)) && !s.isNullable() && getKotlinType(s)?.hasEnhancedNullability() != true && primitiveName != null) {
673681
val label: Label<DbPrimitive> = tw.getLabelFor("@\"type;$primitiveName\"", {
674682
tw.writePrimitives(it, primitiveName)
675683
})
@@ -813,7 +821,7 @@ open class KotlinUsesExtractor(
813821
OperatorNameConventions.INVOKE.asString())
814822

815823
fun getSuffixIfInternal() =
816-
if (f.visibility == DescriptorVisibilities.INTERNAL) {
824+
if (f.visibility == DescriptorVisibilities.INTERNAL && f !is IrConstructor) {
817825
"\$" + getJvmModuleName(f)
818826
} else {
819827
""
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.ir.types.IrSimpleType
4+
import org.jetbrains.kotlin.ir.types.impl.IrTypeBase
5+
6+
fun getKotlinType(s: IrSimpleType) = (s as? IrTypeBase)?.kotlinType
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.ir.types.IrSimpleType
4+
5+
fun getKotlinType(s: IrSimpleType) = s.kotlinType
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.jetbrains.annotations;
2+
import java.lang.annotation.*;
3+
4+
// Stub of @NotNull:
5+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE})
6+
public @interface NotNull { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import org.jetbrains.annotations.NotNull;
2+
3+
public class Test {
4+
5+
public @NotNull Integer f(@NotNull Integer p) { return p; }
6+
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
exprs
2+
| Test.java:5:19:5:25 | Integer | Integer |
3+
| Test.java:5:38:5:44 | Integer | Integer |
4+
| Test.java:5:58:5:58 | p | Integer |
5+
| user.kt:2:3:2:16 | x | int |
6+
| user.kt:2:11:2:11 | t | Test |
7+
| user.kt:2:13:2:16 | <implicit not null> | int |
8+
| user.kt:2:13:2:16 | f(...) | Integer |
9+
| user.kt:2:13:2:16 | int | int |
10+
| user.kt:2:15:2:15 | 5 | int |
11+
| user.kt:3:10:3:10 | x | int |
12+
#select
13+
| Test.java:5:27:5:27 | f | Integer |
14+
| user.kt:1:1:4:1 | f | Test |

0 commit comments

Comments
 (0)