Skip to content

Commit f443509

Browse files
committed
Discard struct types and their fields
1 parent a473fdb commit f443509

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

go/ql/lib/semmle/go/Overlay.qll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,39 @@ private predicate discardLocatable(@locatable locatable) {
5454
discardableLocatable(file, locatable) and discardableFile(path)
5555
)
5656
}
57+
58+
/**
59+
* Holds if the given `structtype` should be discarded, because it is part of
60+
* the overlay base and is only defined in files that were extracted as part of
61+
* the overlay database.
62+
*
63+
* Note that struct types use structural typing. In other words, two different
64+
* files can define defined types whose underlying types are struct types with
65+
* the same fields (names, types and tags), and they will be considered to be
66+
* the exact same struct type.
67+
*/
68+
private predicate discardableStructType(@structtype structtype) {
69+
not isOverlay() and
70+
forex(@definedtype dt, @typeobject to, @ident declIdent, string path |
71+
underlying_type(dt, structtype) and
72+
type_objects(dt, to) and
73+
defs(declIdent, to) and
74+
files(getFile(declIdent), path)
75+
|
76+
discardableFile(path)
77+
)
78+
}
79+
80+
overlay[discard_entity]
81+
private predicate discardStructType(@structtype structtype) { discardableStructType(structtype) }
82+
83+
/**
84+
* Holds if the given `field` should be discarded, because it is defined in a
85+
* struct type which should be discarded.
86+
*/
87+
overlay[discard_entity]
88+
private predicate discardField(@varobject field) {
89+
exists(@structtype structtype | fieldstructs(field, structtype) |
90+
discardableStructType(structtype)
91+
)
92+
}

0 commit comments

Comments
 (0)