Skip to content

Commit 2c2506c

Browse files
committed
Rust: Add Rust SSA inconsistency infrastructure.
1 parent 8102282 commit 2c2506c

File tree

10 files changed

+44
-1
lines changed

10 files changed

+44
-1
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
import codeql.rust.dataflow.Ssa
1+
/**
2+
* @name Static single assignment inconsistencies
3+
* @description Lists the static single assignment inconsistencies in the database. This query is intended for internal use.
4+
* @kind table
5+
* @id rust/diagnostics/ssa-consistency
6+
*/
7+
8+
import codeql.rust.dataflow.Ssa
29
import codeql.rust.dataflow.internal.SsaImpl
310
import Consistency

rust/ql/integration-tests/hello-project/summary.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| Inconsistencies - AST | 0 |
88
| Inconsistencies - CFG | 0 |
99
| Inconsistencies - Path resolution | 0 |
10+
| Inconsistencies - SSA | 0 |
1011
| Inconsistencies - data flow | 0 |
1112
| Lines of code extracted | 6 |
1213
| Lines of user code extracted | 6 |

rust/ql/integration-tests/hello-workspace/summary.cargo.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| Inconsistencies - AST | 0 |
88
| Inconsistencies - CFG | 0 |
99
| Inconsistencies - Path resolution | 0 |
10+
| Inconsistencies - SSA | 0 |
1011
| Inconsistencies - data flow | 0 |
1112
| Lines of code extracted | 9 |
1213
| Lines of user code extracted | 9 |

rust/ql/integration-tests/hello-workspace/summary.rust-project.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| Inconsistencies - AST | 0 |
88
| Inconsistencies - CFG | 0 |
99
| Inconsistencies - Path resolution | 0 |
10+
| Inconsistencies - SSA | 0 |
1011
| Inconsistencies - data flow | 0 |
1112
| Lines of code extracted | 9 |
1213
| Lines of user code extracted | 9 |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name Static single assignment inconsistency counts
3+
* @description Counts the number of static single assignment inconsistencies of each type. This query is intended for internal use.
4+
* @kind diagnostic
5+
* @id rust/diagnostics/ssa-consistency-counts
6+
*/
7+
8+
private import codeql.rust.dataflow.internal.SsaImpl as SsaImpl
9+
10+
// see also `rust/diagnostics/ssa-consistency`, which lists the
11+
// individual inconsistency results.
12+
from string type, int num
13+
where num = SsaImpl::Consistency::getInconsistencyCounts(type)
14+
select type, num

rust/ql/src/queries/summary/Stats.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ private import codeql.rust.internal.AstConsistency as AstConsistency
1010
private import codeql.rust.internal.PathResolutionConsistency as PathResolutionConsistency
1111
private import codeql.rust.controlflow.internal.CfgConsistency as CfgConsistency
1212
private import codeql.rust.dataflow.internal.DataFlowConsistency as DataFlowConsistency
13+
private import codeql.rust.dataflow.internal.SsaImpl as SsaImpl
1314
private import codeql.rust.Concepts
1415
private import codeql.rust.Diagnostics
1516
private import codeql.rust.security.SensitiveData
@@ -57,6 +58,13 @@ int getTotalCfgInconsistencies() {
5758
result = sum(string type | | CfgConsistency::getCfgInconsistencyCounts(type))
5859
}
5960

61+
/**
62+
* Gets a count of the total number of SSA inconsistencies in the database.
63+
*/
64+
int getTotalSsaInconsistencies() {
65+
result = sum(string type | | SsaImpl::Consistency::getInconsistencyCounts(type))
66+
}
67+
6068
/**
6169
* Gets a count of the total number of data flow inconsistencies in the database.
6270
*/
@@ -142,6 +150,8 @@ predicate inconsistencyStats(string key, int value) {
142150
or
143151
key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies()
144152
or
153+
key = "Inconsistencies - SSA" and value = getTotalSsaInconsistencies()
154+
or
145155
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
146156
}
147157

rust/ql/test/query-tests/diagnostics/SsaConsistencyCounts.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/diagnostics/SsaConsistencyCounts.ql

rust/ql/test/query-tests/diagnostics/SummaryStatsReduced.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| Inconsistencies - AST | 0 |
88
| Inconsistencies - CFG | 0 |
99
| Inconsistencies - Path resolution | 0 |
10+
| Inconsistencies - SSA | 0 |
1011
| Inconsistencies - data flow | 0 |
1112
| Lines of code extracted | 60 |
1213
| Lines of user code extracted | 60 |

shared/ssa/codeql/ssa/Ssa.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,13 @@ module Make<LocationSig Location, InputSig<Location> Input> {
14681468
inputRefs = count(BasicBlock bb, int i | AdjacentSsaRefs::adjacentRefPhi(bb, i, _, bbPhi, v)) and
14691469
inputRefs < 2
14701470
}
1471+
1472+
/**
1473+
* Gets counts of inconsistencies of each type.
1474+
*/
1475+
int getInconsistencyCounts(string type) {
1476+
type = "" and result = 0
1477+
}
14711478
}
14721479

14731480
/** Provides the input to `DataFlowIntegration`. */

0 commit comments

Comments
 (0)