Missing tautological compare warnings due to unary operators
The patch mainly focuses on the lack of warnings for -Wtautological-compare. It works fine for positive numbers but doesn't for negative numbers. This is because the warning explicitly checks for an IntegerLiteral AST node, but -1 is represented by a UnaryOperator with an IntegerLiteral sub-Expr. For the below code we have warnings: if (0 == (5 | x)) {} but not for if (0 == (-5 | x)) {} This patch changes the analysis to not look at the AST node directly to see if it is an IntegerLiteral, but instead attempts to evaluate the expression to see if it is an integer constant expression. This handles unary negation signs, but also handles all the other possible operators as well. Fixes #42918 Differential Revision: https://reviews.llvm.org/D130510
Loading
Please sign in to comment