Skip to content

Commit a1de7d4

Browse files
two-heartripatel-fd
authored andcommitted
codeql: detect wrong metrics groups
exactly finds #7408
1 parent 202f400 commit a1de7d4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @name Wrong metrics group in tile
3+
* @description Metrics accessed in a tile should belong to that tile
4+
* @kind problem
5+
* @problem.severity warning
6+
* @precision medium
7+
* @id asymmetric-research/metrics-wrong-group
8+
*/
9+
10+
import cpp
11+
12+
13+
class Tile extends File {
14+
Tile() { this.getBaseName().matches("%_tile.%") }
15+
16+
string getName() {
17+
exists(GlobalVariable v | v.getType().getName() = "fd_topo_run_tile_t" |
18+
v.getLocation().getFile() = this.getFile() and
19+
exists(Field f | f.hasName("name") |
20+
v.getInitializer()
21+
.getExpr()
22+
.(ClassAggregateLiteral)
23+
.getAFieldExpr(f)
24+
.(StringLiteral)
25+
.getValue() = result
26+
)
27+
)
28+
}
29+
30+
string metricsName() {
31+
/* Account for renames in topology.c */
32+
if this.getLocation().getFile().getRelativePath() = "src/discof/resolv/fd_resolv_tile.c"
33+
then result = "resolf"
34+
else
35+
if this.getLocation().getFile().getRelativePath() = "src/discof/bank/fd_bank_tile.c"
36+
then result = "bankf"
37+
else result = this.getName()
38+
}
39+
}
40+
41+
from ArrayExpr arrayAccess, MacroAccess ma, Tile t, string metricsGroup
42+
where
43+
arrayAccess.getArrayBase().toString() = "fd_metrics_tl" and
44+
inmacroexpansion(arrayAccess.getArrayOffset(), ma) and
45+
ma.getMacroName().matches("FD_METRICS_%") and
46+
arrayAccess.getFile() = t.getLocation().getFile() and
47+
metricsGroup = ma.getMacroName().splitAt("_", 3) and
48+
metricsGroup.toLowerCase() != t.metricsName()
49+
select arrayAccess, "Metrics group " + metricsGroup + " unexpected for tile " + t.getName()

0 commit comments

Comments
 (0)