C++: More principled macro exclusion

We no longer exclude macros based on their name, which means we can now
find results inside arguments to the `likely` macro in Linux (except
that Linux is compiled with `-fno-strict-overflow`).
This commit is contained in:
Jonas Jensen
2019-11-13 13:55:29 +01:00
parent db33053422
commit 1b849dbf0e

View File

@@ -12,6 +12,7 @@
import cpp
private import semmle.code.cpp.valuenumbering.GlobalValueNumbering
private import semmle.code.cpp.commons.Exclusions
from RelationalOperation ro, PointerAddExpr add, Expr expr1, Expr expr2
where
@@ -19,13 +20,8 @@ where
add.getAnOperand() = expr1 and
ro.getAnOperand() = expr2 and
globalValueNumber(expr1) = globalValueNumber(expr2) and
// Exclude macros except for assert macros.
// TODO: port that location-based macro check we have in another query. Then
// we don't need to special-case on names.
not exists(MacroInvocation mi |
mi.getAnAffectedElement() = add and
not mi.getMacroName().toLowerCase().matches("%assert%")
) and
// Exclude macros but not their arguments
not isFromMacroDefinition(ro) and
// There must be a compilation of this file without a flag that makes pointer
// overflow well defined.
exists(Compilation c | c.getAFileCompiled() = ro.getFile() |