-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++: Initial telemetry queries #17892
base: main
Are you sure you want to change the base?
Conversation
9409641
to
913056a
Compare
913056a
to
8035a7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there are specific reason we're not re-using some of the functionality already present in cpp/ql/src/Diagnostics
?
| identifier 'nsf2' is undefined | 1.0 | | ||
| identifier 'so_is_this' is undefined | 1.0 | | ||
| identifier 'uint32_t' is undefined | 1.0 | | ||
| too few arguments in function call | 1.0 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the values here floats? It seems like these are just discrete counts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because all metrics are floats in general. But it might be worth specialising to int-metrics and float-metrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems a very bad design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 841c678 any better?
The code in |
Not even the libraries in that directory are of use? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions about the used tags.
cpp/ql/src/Telemetry/Diagnostics.qll
Outdated
* Typically this is due to a missing include. | ||
*/ | ||
class CannotOpenFile extends CompilerError { | ||
CannotOpenFile() { this.hasTag("cannot_open_file") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also cover cannot_open_file_reason
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have a look at these tags 👍
cpp/ql/src/Telemetry/Diagnostics.qll
Outdated
* Currently unused. | ||
*/ | ||
class UndefinedIdentifier extends CompilerError { | ||
UndefinedIdentifier() { this.hasTag("undefined_identifier") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a number of other ..._undefined_identifier
tags, shouldn't those be covered too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had a search through the front end source code, and the other ec_undefined_
errors are all at warning or remark level (e.g. ec_undefined_preproc_id
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about ec_range_based_for_undefined_identifier
and ec_for_each_undefined_identifier
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I'll just delete UndefinedIdentifier
as it's unused and not worth creating a test for.
cpp/ql/src/Telemetry/Diagnostics.qll
Outdated
* A syntax error. | ||
*/ | ||
class SyntaxError extends CompilerError { | ||
SyntaxError() { this.getTag().matches("exp_%") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does exp_
cover all possible syntax errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no. Searching for syntax_error(ec_
reveals various other syntax errors that I will add.
Well, telemetry is a bit simpler because it's a question of dumping counts and raw data, so we don't need to refine them in the same way. |
201f282
to
ac692ee
Compare
from CppMetrics::MissingIncludeCount e | ||
select e.getIncludeText(), e.getValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned that this might completely blow up on real-world projects to such an extent that the SARIF will be rejected when uploaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I've limited the results to the top 500 - not sure if that's a sensible number or not.
from CppMetrics::ErrorCount m | ||
select m.toString(), m.getValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned that this might completely blow up on real-world projects to such an extent that the SARIF will be rejected when uploaded. Especially because the error messages can in principle be several lines long.
4fc90ca
to
8029eb2
Compare
This adds new internal telemetry queries, so should not need a changenote.
It loosely follows the examples in https://github.com/github/codeql/tree/main/java/ql/src/Telemetry and https://github.com/github/codeql/tree/main/csharp/ql/src/Telemetry.
As a new idea,
Metrics.qll
uses QL classes a bit more heavily, instead of binary predicates, but obviously they boil down to the same thing.We don't (yet) emit a diagnostic warning about low quality databases.
Note that qltest can't test for missing includes, since these lead to a catastrophic error by default.
Fixes https://github.com/github/codeql-c-team/issues/2471
Pull Request checklist
All query authors
[ ] A change note is added if necessary. See the documentation in this repository.[ ] All new queries have appropriate.qhelp
. See the documentation in this repository.Internal query authors only
[ ] Autofixes generated based on these changes are valid, only needed if this PR makes significant changes to.ql
,.qll
, or.qhelp
files. See the documentation (internal access required).[ ] Adding a new query? Consider also adding the query to autofix.