Skip to content

Commit 4c8926d

Browse files
authored
Merge pull request #9720 from jketema/linkage
C++: Support link targets for global and namespace variables
2 parents 5840377 + 284c8dd commit 4c8926d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added support for getting the link targets of global and namespace variables.

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
@@ -473,6 +473,9 @@ class GlobalOrNamespaceVariable extends Variable, @globalvariable {
473473
override Type getType() { globalvariables(underlyingElement(this), unresolveElement(result), _) }
474474

475475
override Element getEnclosingElement() { none() }
476+
477+
/** Gets a link target which compiled or referenced this global or namespace variable. */
478+
LinkTarget getALinkTarget() { this = result.getAGlobalOrNamespaceVariable() }
476479
}
477480

478481
/**

0 commit comments

Comments
 (0)