Skip to content

Commit ad6988f

Browse files
authored
Merge pull request #20995 from github/idrissrio/cpp/overlay/locations
C/C++ overlay: Add multiloc declaration to Overlay.qll
2 parents ce2c149 + 3f372d2 commit ad6988f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,39 @@ private string getLocationFilePath(@location_default loc) {
2020
*/
2121
overlay[local]
2222
private string getSingleLocationFilePath(@element e) {
23-
// @var_decl has a direct location in the var_decls relation
24-
exists(@location_default loc | var_decls(e, _, _, _, loc) | result = getLocationFilePath(loc))
25-
//TODO: add other kinds of elements with single locations
23+
exists(@location_default loc |
24+
var_decls(e, _, _, _, loc)
25+
or
26+
fun_decls(e, _, _, _, loc)
27+
or
28+
type_decls(e, _, loc)
29+
or
30+
namespace_decls(e, _, loc, _)
31+
or
32+
macroinvocations(e, _, loc, _)
33+
or
34+
preprocdirects(e, _, loc)
35+
|
36+
result = getLocationFilePath(loc)
37+
)
2638
}
2739

2840
/**
2941
* Gets the file path for an element with potentially multiple locations.
3042
*/
3143
overlay[local]
3244
private string getMultiLocationFilePath(@element e) {
33-
// @variable gets its location(s) from its @var_decl(s)
34-
exists(@var_decl vd, @location_default loc | var_decls(vd, e, _, _, loc) |
45+
exists(@location_default loc |
46+
exists(@var_decl vd | var_decls(vd, e, _, _, loc))
47+
or
48+
exists(@fun_decl fd | fun_decls(fd, e, _, _, loc))
49+
or
50+
exists(@type_decl td | type_decls(td, e, loc))
51+
or
52+
exists(@namespace_decl nd | namespace_decls(nd, e, loc, _))
53+
|
3554
result = getLocationFilePath(loc)
3655
)
37-
//TODO: add other kinds of elements with multiple locations
3856
}
3957

4058
/**

0 commit comments

Comments
 (0)