mirror of
https://github.com/github/codeql.git
synced 2026-03-23 07:56:54 +01:00
Follow a naming structure similar to the data flow library: - `ControlFlowNode` -> `ControlFlow::Node`. - `CallableEntryNode` -> `ControlFlow::Nodes::EntryNode`. - `CallableExitNode` -> `ControlFlow::Nodes::ExitNode`. - `ControlFlowEdgeType` -> `ControlFlow::SuccessorType`. - `ControlFlowEdgeSuccessor` -> `ControlFlow::SuccessorTypes::NormalSuccessor`. - `ControlFlowEdgeConditional -> ControlFlow::SuccessorTypes::ConditionalSuccessor`. - `ControlFlowEdgeBoolean` -> `ControlFlow::SuccessorTypes::BooleanSuccessor`. - `ControlFlowEdgeNullness` -> `ControlFlow::SuccessorTypes::NullnessSuccessor`. - `ControlFlowEdgeMatching` -> `ControlFlow::SuccessorTypes::MatchingSuccessor`. - `ControlFlowEdgeEmptiness` -> `ControlFlow::SuccessorTypes::EmptinessSuccessor`. - `ControlFlowEdgeReturn` -> `ControlFlow::SuccessorTypes::ReturnSuccessor`. - `ControlFlowEdgeBreak` -> `ControlFlow::SuccessorTypes::BreakSuccessor`. - `ControlFlowEdgeContinue` -> `ControlFlow::SuccessorTypes::ContinueSuccessor`. - `ControlFlowEdgeGotoLabel` -> `ControlFlow::SuccessorTypes::GotoLabelSuccessor`. - `ControlFlowEdgeGotoCase` -> `ControlFlow::SuccessorTypes::GotoCaseSuccessor`. - `ControlFlowEdgeGotoDefault` -> `ControlFlow::SuccessorTypes::GotoDefaultSuccessor`. - `ControlFlowEdgeException` -> `ControlFlow::SuccessorTypes::ExceptionSuccessor`
32 lines
1.1 KiB
Plaintext
32 lines
1.1 KiB
Plaintext
import csharp
|
|
|
|
/** "Naive" parameter-use implementation. */
|
|
predicate parameterReaches(Parameter p, ControlFlow::Node cfn) {
|
|
cfn = p.getCallable().getEntryPoint().getASuccessor()
|
|
or
|
|
exists(ControlFlow::Node mid |
|
|
parameterReaches(p, mid) |
|
|
not mid = any(AssignableDefinition ad | ad.getTarget() = p and ad.isCertain()).getAControlFlowNode() and
|
|
cfn = mid.getASuccessor()
|
|
)
|
|
}
|
|
|
|
predicate parameterUsePair(Parameter p, AssignableRead read) {
|
|
parameterReaches(p, read.getAControlFlowNode()) and
|
|
read.getTarget() = p
|
|
}
|
|
|
|
private LocalScopeVariableRead getAReachableUncertainRead(AssignableDefinitions::ImplicitParameterDefinition p) {
|
|
exists(Ssa::Definition ssaDef |
|
|
p = ssaDef.getAnUltimateDefinition().(Ssa::ExplicitDefinition).getADefinition() |
|
|
result = ssaDef.getARead()
|
|
)
|
|
}
|
|
|
|
from AssignableDefinitions::ImplicitParameterDefinition p, AssignableRead read, string s
|
|
where
|
|
(read = getAReachableUncertainRead(p) and not parameterUsePair(p.getParameter(), read) and s = "not a param/use pair")
|
|
or
|
|
(parameterUsePair(p.getParameter(), read) and not read = getAReachableUncertainRead(p) and s = "missing param/use pair")
|
|
select p, read, s
|