Merge pull request #1285 from geoffw0/rnperf

CPP: Improve performance of RedundantNullCheckSimple.ql
This commit is contained in:
Jonas Jensen
2019-04-29 08:41:43 +02:00
committed by GitHub

View File

@@ -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"