Skip to content

[clang][dataflow] Diagnose branch conditions using the data-flow framework #141602

@Discookie

Description

@Discookie

I'm currently working on a prototype dead-code check using the data-flow framework: #139068
The check works by finding loop conditions that are always true or always false, and emitting an error there.
However, the dataflow framework's Diagnoser entity doesn't have the ability to diagnose specifically loop conditions. It only has the ability to diagnose expressions.
(The workaround for this is to tag the loop conditions separately, but it's most definitely not a sound workaround, since the tags are also visible in unexpected places.)

There needs to be a way to diagnose specifically loop conditions, in a way that is known to the Diagnoser.
Ideally this diagnosis would be done in a way where both the normal Expr diagnoser, and the condition diagnoser are part of the same function.

Currently I'm thinking to add another overload to operator() in the Diagnoser class, into the DiagnosisCallback here:

template <typename AnalysisT, typename Diagnostic>
using DiagnosisCallback = llvm::function_ref<llvm::SmallVector<Diagnostic>(
const CFGElement &, ASTContext &,
const TransferStateForDiagnostics<typename AnalysisT::Lattice> &)>;

But at that point it might be better to move the branch-diagnoser into a named function inside the same class.

Metadata

Metadata

Assignees

Labels

clang:dataflowClang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions