Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions go/ql/lib/semmle/go/Overlay.qll
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,39 @@ private predicate discardLocatable(@locatable locatable) {
discardableLocatable(file, locatable) and discardableFile(path)
)
}

/**
* Holds if the given `structtype` should be discarded, because it is part of
* the overlay base and is only defined in files that were extracted as part of
* the overlay database.
*
* Note that struct types use structural typing. In other words, two different
* files can define defined types whose underlying types are struct types with
* the same fields (names, types and tags), and they will be considered to be
* the exact same struct type.
*/
private predicate discardableStructType(@structtype structtype) {
not isOverlay() and
forex(@definedtype dt, @typeobject to, @ident declIdent, string path |
underlying_type(dt, structtype) and
type_objects(dt, to) and
defs(declIdent, to) and
files(getFile(declIdent), path)
|
discardableFile(path)
)
}

overlay[discard_entity]
private predicate discardStructType(@structtype structtype) { discardableStructType(structtype) }

/**
* Holds if the given `field` should be discarded, because it is defined in a
* struct type which should be discarded.
*/
overlay[discard_entity]
private predicate discardField(@varobject field) {
exists(@structtype structtype | fieldstructs(field, structtype) |
discardableStructType(structtype)
)
}
Loading