Skip to content

Commit 5e815fb

Browse files
authored
Merge branch 'main' into atorralba/static-init-vector-fix
2 parents c35fbf9 + 72c2040 commit 5e815fb

File tree

88 files changed

+9929
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+9929
-621
lines changed

cpp/downgrades/f96ad9b2da43bbc9e55a72a165febd270ae07981/old.dbscheme

Lines changed: 2136 additions & 0 deletions
Large diffs are not rendered by default.

cpp/downgrades/f96ad9b2da43bbc9e55a72a165febd270ae07981/semmlecode.cpp.dbscheme

Lines changed: 2131 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: Add relation for orphaned local variables
2+
compatibility: full
3+
orphaned_variables.rel: delete
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/File.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ class Folder extends Container, @folder {
218218
class File extends Container, @file {
219219
override string getAbsolutePath() { files(underlyingElement(this), result) }
220220

221-
override string toString() { result = Container.super.toString() }
222-
223221
override string getAPrimaryQlClass() { result = "File" }
224222

225223
override Location getLocation() {

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ class LocalVariable extends LocalScopeVariable, @localvariable {
398398
exists(DeclStmt s | s.getADeclaration() = this and s.getEnclosingFunction() = result)
399399
or
400400
exists(ConditionDeclExpr e | e.getVariable() = this and e.getEnclosingFunction() = result)
401+
or
402+
orphaned_variables(underlyingElement(this), unresolveElement(result))
401403
}
402404
}
403405

@@ -471,6 +473,9 @@ class GlobalOrNamespaceVariable extends Variable, @globalvariable {
471473
override Type getType() { globalvariables(underlyingElement(this), unresolveElement(result), _) }
472474

473475
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() }
474479
}
475480

476481
/**

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ autoderivation(
523523
int derivation_type: @type ref
524524
);
525525

526+
orphaned_variables(
527+
int var: @localvariable ref,
528+
int function: @function ref
529+
)
530+
526531
enumconstants(
527532
unique int id: @enumconstant,
528533
int parent: @usertype ref,

0 commit comments

Comments
 (0)