Skip to content

Commit e90e313

Browse files
smowtonowen-mc
authored andcommitted
Simplify ensureCorrectTypeInfo
1 parent e46ec5a commit e90e313

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -276,42 +276,23 @@ module SourceSinkInterpretationInput implements
276276
or
277277
exists(DataFlow::Write fw | fw.writesField(recv, sse.asEntity(), _))
278278
) and
279-
exists(string pkg, string typename, boolean subtypes, Type syntacticRecvBaseType |
279+
exists(string pkg, string typename, boolean subtypes, Type syntacticRecvBaseType, Type targetType |
280280
sse.hasTypeInfo(pkg, typename, subtypes) and
281+
targetType.hasQualifiedName(pkg, typename) and
281282
syntacticRecvBaseType = lookThroughPointerType(getSyntacticRecv(recv).getType())
282283
|
283284
subtypes = [true, false] and
284-
syntacticRecvBaseType.hasQualifiedName(pkg, typename)
285+
syntacticRecvBaseType = targetType
285286
or
286287
subtypes = true and
287288
(
288289
// `syntacticRecvBaseType`'s underlying type might be an interface type and `sse`
289290
// might be a method defined on an interface which is a subtype of it.
290-
exists(Type t |
291-
t = syntacticRecvBaseType.getUnderlyingType().(InterfaceType).getAnEmbeddedInterface() and
292-
t.hasQualifiedName(pkg, typename) and
293-
sse.asEntity().(Method).hasQualifiedName(pkg, typename, _)
294-
)
291+
targetType = syntacticRecvBaseType.getUnderlyingType().(InterfaceType).getAnEmbeddedInterface()
295292
or
296293
// `syntacticRecvBaseType`'s underlying type might be a struct type and `sse`
297294
// might be a promoted method or field.
298-
exists(StructType st, Field field1, Field field2, int depth1, int depth2, Type t1, Type t2 |
299-
st = syntacticRecvBaseType.getUnderlyingType() and
300-
field1 = st.getFieldAtDepth(_, depth1) and
301-
field2 = st.getFieldAtDepth(_, depth2) and
302-
t1 = lookThroughPointerType(field1.getType()) and
303-
t2 = lookThroughPointerType(field2.getType()) and
304-
(
305-
field1 = field2
306-
or
307-
field2 = t1.getUnderlyingType().(StructType).getFieldAtDepth(_, depth2 - depth1 - 1)
308-
) and
309-
matchTypeInfo(sse, t1)
310-
|
311-
sse.asEntity().(Method).getReceiverBaseType() = t2
312-
or
313-
sse.asEntity().(Field).getDeclaringType() = t2.getUnderlyingType()
314-
)
295+
syntacticRecvBaseType.getUnderlyingType().(StructType).hasEmbeddedField(targetType, _)
315296
)
316297
)
317298
}
@@ -343,15 +324,6 @@ module SourceSinkInterpretationInput implements
343324
.getBaseInstruction()
344325
}
345326

346-
bindingset[sse, t]
347-
pragma[inline_late]
348-
private predicate matchTypeInfo(SourceOrSinkElement sse, Type t) {
349-
exists(string pkg, string typename |
350-
sse.hasTypeInfo(pkg, typename, true) and
351-
t.hasQualifiedName(pkg, typename)
352-
)
353-
}
354-
355327
/** Provides additional sink specification logic. */
356328
bindingset[c]
357329
predicate interpretOutput(string c, InterpretNode mid, InterpretNode node) {

0 commit comments

Comments
 (0)