Skip to content

Commit 38b4c02

Browse files
committed
C++: Support link targets for global and namespace variables
1 parent fb9a348 commit 38b4c02

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cpp/ql/lib/semmle/code/cpp/Linkage.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ class LinkTarget extends @link_target {
4141
* translation units which contributed to this link target.
4242
*/
4343
Class getAClass() { link_parent(unresolveElement(result), this) }
44+
45+
/**
46+
* Gets a global or namespace variable which was compiled into this
47+
* link target, or had its declaration included by one of the translation
48+
* units which contributed to this link target.
49+
*/
50+
GlobalOrNamespaceVariable getAGlobalOrNamespaceVariable() {
51+
link_parent(unresolveElement(result), this)
52+
}
4453
}
4554

4655
/**

cpp/ql/lib/semmle/code/cpp/Variable.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ class GlobalOrNamespaceVariable extends Variable, @globalvariable {
471471
override Type getType() { globalvariables(underlyingElement(this), unresolveElement(result), _) }
472472

473473
override Element getEnclosingElement() { none() }
474+
475+
/** Gets a link target which compiled or referenced this global or namespace variable. */
476+
LinkTarget getALinkTarget() { this = result.getAGlobalOrNamespaceVariable() }
474477
}
475478

476479
/**

0 commit comments

Comments
 (0)