From c67122b3f1bcb695f5fbf1da03cf8043193ff099 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Mon, 23 Mar 2026 12:14:11 +0100 Subject: [PATCH] C++: Add expressions with type data to cpp/extraction-information --- cpp/ql/src/Telemetry/DatabaseQuality.qll | 27 +++++++++++++++++++- cpp/ql/src/Telemetry/ExtractorInformation.ql | 5 +++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cpp/ql/src/Telemetry/DatabaseQuality.qll b/cpp/ql/src/Telemetry/DatabaseQuality.qll index 003b7dc01d19..be44a9431aab 100644 --- a/cpp/ql/src/Telemetry/DatabaseQuality.qll +++ b/cpp/ql/src/Telemetry/DatabaseQuality.qll @@ -1,9 +1,14 @@ import cpp import codeql.util.ReportStats +/** A file that is included in the quality statistics. */ +private class RelevantFile extends File { + RelevantFile() { this.fromSource() and exists(this.getRelativePath()) } +} + module CallTargetStats implements StatsSig { private class RelevantCall extends Call { - RelevantCall() { this.getFile() = any(File f | f.fromSource() and exists(f.getRelativePath())) } + RelevantCall() { this.getFile() instanceof RelevantFile } } // We assume that calls with an implicit target are calls that could not be @@ -22,4 +27,24 @@ module CallTargetStats implements StatsSig { string getNotOkText() { result = "calls with missing call target" } } +private class SourceExpr extends Expr { + SourceExpr() { this.getFile() instanceof RelevantFile } +} + +predicate find(SourceExpr e) { not hasGoodType(e) } + +private predicate hasGoodType(Expr e) { not e.getType() instanceof ErroneousType } + +module ExprTypeStats implements StatsSig { + int getNumberOfOk() { result = count(SourceExpr e | hasGoodType(e)) } + + int getNumberOfNotOk() { result = count(SourceExpr e | not hasGoodType(e)) } + + string getOkText() { result = "expressions with known type" } + + string getNotOkText() { result = "expressions with unknown type" } +} + module CallTargetStatsReport = ReportStats; + +module ExprTypeStatsReport = ReportStats; diff --git a/cpp/ql/src/Telemetry/ExtractorInformation.ql b/cpp/ql/src/Telemetry/ExtractorInformation.ql index 6e134ccd05f7..a82b3b86acee 100644 --- a/cpp/ql/src/Telemetry/ExtractorInformation.ql +++ b/cpp/ql/src/Telemetry/ExtractorInformation.ql @@ -14,7 +14,10 @@ where ( CallTargetStatsReport::numberOfOk(key, value) or CallTargetStatsReport::numberOfNotOk(key, value) or - CallTargetStatsReport::percentageOfOk(key, value) + CallTargetStatsReport::percentageOfOk(key, value) or + ExprTypeStatsReport::numberOfOk(key, value) or + ExprTypeStatsReport::numberOfNotOk(key, value) or + ExprTypeStatsReport::percentageOfOk(key, value) ) and /* Infinity */ value != 1.0 / 0.0 and