Skip to content

Commit fbae0f5

Browse files
tamasvajksmowton
authored andcommitted
Revert dataflow changes, extract actual iterator function
1 parent 538e059 commit fbae0f5

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,23 @@ open class KotlinFileExtractor(
13471347
return result
13481348
}
13491349

1350+
private fun findTopLevelFunctionOrWarn(functionFilter: String, type: String, warnAgainstElement: IrElement): IrFunction? {
1351+
1352+
val fn = pluginContext.referenceFunctions(FqName(functionFilter))
1353+
.firstOrNull { it.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type }
1354+
?.owner
1355+
1356+
if (fn != null) {
1357+
if (fn.parentClassOrNull != null) {
1358+
extractExternalClassLater(fn.parentAsClass)
1359+
}
1360+
} else {
1361+
logger.errorElement("Couldn't find JVM intrinsic function $functionFilter in $type", warnAgainstElement)
1362+
}
1363+
1364+
return fn
1365+
}
1366+
13501367
val javaLangString by lazy {
13511368
val result = pluginContext.referenceClass(FqName("java.lang.String"))?.owner
13521369
result?.let { extractExternalClassLater(it) }
@@ -1860,6 +1877,11 @@ open class KotlinFileExtractor(
18601877
}
18611878
}
18621879
}
1880+
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "iterator") && c.origin == IrStatementOrigin.FOR_LOOP_ITERATOR -> {
1881+
findTopLevelFunctionOrWarn("kotlin.jvm.internal.iterator", "kotlin.jvm.internal.ArrayIteratorKt", c)?.let { iteratorFn ->
1882+
extractRawMethodAccess(iteratorFn, c, callable, parent, idx, enclosingStmt, listOf(c.dispatchReceiver), null, null, listOf((c.dispatchReceiver!!.type as IrSimpleType).arguments.first().typeOrNull!!))
1883+
}
1884+
}
18631885
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "get") && c.origin == IrStatementOrigin.GET_ARRAY_ELEMENT -> {
18641886
val id = tw.getFreshIdLabel<DbArrayaccess>()
18651887
val type = useType(c.type)

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,6 @@ private predicate canContainBool(Type t) {
205205
any(BooleanType b).(RefType).getASourceSupertype+() = t
206206
}
207207

208-
private predicate isArray(Type t) {
209-
t instanceof Array or
210-
t.(RefType).getSourceDeclaration().hasQualifiedName("kotlin", "Array")
211-
}
212-
213208
/**
214209
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
215210
* a node of type `t1` to a node of type `t2`.
@@ -226,9 +221,6 @@ predicate compatibleTypes(Type t1, Type t2) {
226221
erasedHaveIntersection(e1, e2)
227222
or
228223
canContainBool(e1) and canContainBool(e2)
229-
or
230-
// Make java array and `kotlin.Array` types compatible.
231-
isArray(e1) and isArray(e2)
232224
)
233225
}
234226

java/ql/lib/semmle/code/java/frameworks/KotlinStdLib.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ private import semmle.code.java.dataflow.ExternalFlow
55

66
private class KotlinStdLibSummaryCsv extends SummaryModelCsv {
77
override predicate row(string row) {
8-
row = ["kotlin;Array;false;iterator;();;Argument[-1].ArrayElement;ReturnValue.Element;value"]
8+
row =
9+
[
10+
"kotlin.jvm.internal;ArrayIteratorKt;false;iterator;(Object[]);;Argument[0].ArrayElement;ReturnValue.Element;value"
11+
]
912
}
1013
}

0 commit comments

Comments
 (0)