Skip to content

Commit 4ad25e4

Browse files
committed
C/C++ overlay: Address review comments
1 parent eac06dd commit 4ad25e4

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

cpp/ql/lib/semmle/code/cpp/internal/Overlay.qll

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,24 @@ private string getMultiLocationFilePath(@element e) {
3737
//TODO: add other kinds of elements with multiple locations
3838
}
3939

40-
/** Holds if `e` exists in the base variant. */
41-
overlay[local]
42-
private predicate existsInBase(@element e) {
43-
not isOverlay() and
44-
(exists(getSingleLocationFilePath(e)) or exists(getMultiLocationFilePath(e)))
45-
}
46-
4740
/**
48-
* Discard an element with a single location if it is in a changed file.
41+
* A local helper predicate that holds in the base variant and never in the
42+
* overlay variant.
4943
*/
50-
overlay[discard_entity]
51-
private predicate discardSingleLocationElement(@element e) {
52-
existsInBase(e) and
53-
overlayChangedFiles(getSingleLocationFilePath(e))
54-
}
44+
overlay[local]
45+
private predicate holdsInBase() { not isOverlay() }
5546

5647
/**
57-
* Discard an element with multiple locations only if all its locations are in changed files.
48+
* Discards an element from the base variant if:
49+
* - It has a single location in a changed file, or
50+
* - All of its locations are in changed files.
5851
*/
5952
overlay[discard_entity]
60-
private predicate discardMultiLocationElement(@element e) {
61-
existsInBase(e) and
62-
exists(getMultiLocationFilePath(e)) and
63-
forall(string path | path = getMultiLocationFilePath(e) | overlayChangedFiles(path))
53+
private predicate discardElement(@element e) {
54+
holdsInBase() and
55+
(
56+
overlayChangedFiles(getSingleLocationFilePath(e))
57+
or
58+
forex(string path | path = getMultiLocationFilePath(e) | overlayChangedFiles(path))
59+
)
6460
}

0 commit comments

Comments
 (0)