From e6fd1582780c98e16196d1766622f93cdf88e02e Mon Sep 17 00:00:00 2001 From: two-heart <12869538+two-heart@users.noreply.github.com> Date: Mon, 24 Nov 2025 19:06:49 +0100 Subject: [PATCH] codeql: detect wrong metrics groups exactly finds #7408 --- contrib/codeql/nightly/WrongMetricsGroup.ql | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 contrib/codeql/nightly/WrongMetricsGroup.ql diff --git a/contrib/codeql/nightly/WrongMetricsGroup.ql b/contrib/codeql/nightly/WrongMetricsGroup.ql new file mode 100644 index 00000000000..33811b04492 --- /dev/null +++ b/contrib/codeql/nightly/WrongMetricsGroup.ql @@ -0,0 +1,49 @@ +/** + * @name Wrong metrics group in tile + * @description Metrics accessed in a tile should belong to that tile + * @kind problem + * @problem.severity warning + * @precision medium + * @id asymmetric-research/metrics-wrong-group + */ + +import cpp + + +class Tile extends File { + Tile() { this.getBaseName().matches("%_tile.%") } + + string getName() { + exists(GlobalVariable v | v.getType().getName() = "fd_topo_run_tile_t" | + v.getLocation().getFile() = this.getFile() and + exists(Field f | f.hasName("name") | + v.getInitializer() + .getExpr() + .(ClassAggregateLiteral) + .getAFieldExpr(f) + .(StringLiteral) + .getValue() = result + ) + ) + } + + string metricsName() { + /* Account for renames in topology.c */ + if this.getLocation().getFile().getRelativePath() = "src/discof/resolv/fd_resolv_tile.c" + then result = "resolf" + else + if this.getLocation().getFile().getRelativePath() = "src/discof/bank/fd_bank_tile.c" + then result = "bankf" + else result = this.getName() + } +} + +from ArrayExpr arrayAccess, MacroAccess ma, Tile t, string metricsGroup +where + arrayAccess.getArrayBase().toString() = "fd_metrics_tl" and + inmacroexpansion(arrayAccess.getArrayOffset(), ma) and + ma.getMacroName().matches("FD_METRICS_%") and + arrayAccess.getFile() = t.getLocation().getFile() and + metricsGroup = ma.getMacroName().splitAt("_", 3) and + metricsGroup.toLowerCase() != t.metricsName() +select arrayAccess, "Metrics group " + metricsGroup + " unexpected for tile " + t.getName()