Files
codeql/csharp/ql/consistency-queries/SsaConsistency.ql
Anders Schack-Mulligen 00b8c80c24 SSA/C#/Ruby/Rust: Clean up SSA consistency queries.
The RelevantDefinition class is no longer needed since the introduction
of LocationSig.
2025-03-04 12:24:23 +01:00

20 lines
815 B
Plaintext

import csharp
import semmle.code.csharp.dataflow.internal.SsaImpl as Impl
import Impl::Consistency
import Ssa
query predicate localDeclWithSsaDef(LocalVariableDeclExpr d) {
// Local variables in C# must be initialized before every use, so uninitialized
// local variables should not have an SSA definition, as that would imply that
// the declaration is live (can reach a use without passing through a definition)
exists(ExplicitDefinition def |
d = def.getADefinition().(AssignableDefinitions::LocalVariableDefinition).getDeclaration()
|
not d = any(ForeachStmt fs).getVariableDeclExpr() and
not d = any(SpecificCatchClause scc).getVariableDeclExpr() and
not d.getVariable().getType() instanceof Struct and
not d instanceof PatternExpr and
not d.getVariable().isCaptured()
)
}