[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 28 13:37:54 PDT 2021


rsmith added a comment.

When this change returns, I'd like to see a different implementation strategy. Running a recursive AST visitation after the fact is generally not the right way to look for this kind of issue; adding an extra pass to speculatively hunt for each kind of warning we might want to issue is too expensive. Instead, I think we should do something simpler and cheaper, such as tracking, for each variable in scope, the number of potentially-evaluated non-assignment references to that variable. For example:

- in `DoMarkVarDeclReferenced`, increment a per-variable counter if the variable is a local and the reference is an odr-use
- in `IgnoredValueConversions`, if we're discarding a potentially-evaluated assignment or increment expression acting on a local variable, decrement the counter for that variable
- in `ActOnPopScope`, or perhaps in `DiagnoseUnusedDecl`, when we're diagnosing unused variables, also diagnose set-but-not-used variables (where the variable is marked as used but the counter is equal to zero)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100581/new/

https://reviews.llvm.org/D100581



More information about the cfe-commits mailing list