Skip to content

Commit 39136f3

Browse files
committed
C/C++ overlay: Add basic Overlay.qll file
1 parent adc13e3 commit 39136f3

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

cpp/ql/lib/cpp.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ import semmle.code.cpp.Preprocessor
7474
import semmle.code.cpp.Iteration
7575
import semmle.code.cpp.NameQualifiers
7676
import DefaultOptions
77+
private import semmle.code.cpp.internal.Overlay
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Defines entity discard predicates for C++ overlay analysis.
3+
*/
4+
5+
/**
6+
* Holds always for the overlay variant and never for the base variant.
7+
* This local predicate is used to define local predicates that behave
8+
* differently for the base and overlay variant.
9+
*/
10+
overlay[local]
11+
predicate isOverlay() { databaseMetadata("isOverlay", "true") }
12+
13+
/** Gets the file path for a location. */
14+
overlay[local]
15+
private string getLocationFilePath(@location_default loc) {
16+
exists(@file file | locations_default(loc, file, _, _, _, _) | files(file, result))
17+
}
18+
19+
/**
20+
* Gets the file path for an element in the base variant.
21+
*/
22+
overlay[local]
23+
private string getElementPathInBase(@element e) {
24+
not isOverlay() and
25+
exists(@location_default loc |
26+
// Direct location (declarations)
27+
var_decls(e, _, _, _, loc)
28+
or
29+
// Indirect location (entities)
30+
exists(@var_decl vd | var_decls(vd, e, _, _, _) | var_decls(vd, _, _, _, loc))
31+
|
32+
result = getLocationFilePath(loc)
33+
)
34+
}
35+
36+
/**
37+
* Discard any element from the base that is in a changed file.
38+
*/
39+
overlay[discard_entity]
40+
private predicate discardElement(@element e) { overlayChangedFiles(getElementPathInBase(e)) }

0 commit comments

Comments
 (0)