mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Merge pull request #1285 from geoffw0/rnperf
CPP: Improve performance of RedundantNullCheckSimple.ql
This commit is contained in:
@@ -56,17 +56,22 @@ predicate explicitNullTestOfInstruction(Instruction checked, Instruction bool) {
|
||||
)
|
||||
}
|
||||
|
||||
predicate candidateResult(LoadInstruction checked, SingleValuedInstruction sourceValue)
|
||||
{
|
||||
explicitNullTestOfInstruction(checked, _) and
|
||||
not checked.getAST().isInMacroExpansion() and
|
||||
sourceValue = checked.getSourceValue()
|
||||
}
|
||||
|
||||
from LoadInstruction checked, LoadInstruction deref, SingleValuedInstruction sourceValue
|
||||
where
|
||||
explicitNullTestOfInstruction(checked, _) and
|
||||
candidateResult(checked, sourceValue) and
|
||||
sourceValue = deref.getSourceAddress().(LoadInstruction).getSourceValue() and
|
||||
sourceValue = checked.getSourceValue() and
|
||||
// This also holds if the blocks are equal, meaning that the check could come
|
||||
// before the deref. That's still not okay because when they're in the same
|
||||
// basic block then the deref is unavoidable even if the check concluded that
|
||||
// the pointer was null. To follow this idea to its full generality, we
|
||||
// should also give an alert when `check` post-dominates `deref`.
|
||||
deref.getBlock().dominates(checked.getBlock()) and
|
||||
not checked.getAST().isInMacroExpansion()
|
||||
deref.getBlock().dominates(checked.getBlock())
|
||||
select checked, "This null check is redundant because the value is $@ in any case", deref,
|
||||
"dereferenced here"
|
||||
|
||||
Reference in New Issue
Block a user