analyzer: Add Pointer Difference Folding
The static analyzer now folds pointer subtraction expressions, allowing it to better handle `std::string::size()` on non-empty strings.
The static analyzer can now simplify expressions involving pointer subtraction. Specifically, it can fold (X + Y) - X to Y. This allows -fanalyzer to reason about std::string::size() when called on non-empty strings. This improvement enhances the analyzer’s ability to detect potential issues in code that uses pointer arithmetic.
In Details
This commit modifies region-model-manager.cc by adding pointer difference folding to the -fanalyzer. The maybe_fold_binop function now folds expressions of the form (X POINTER_PLUS Y) POINTER_DIFF_EXPR X to Y. This enables the analyzer to handle std::string size() calls on non-empty strings by simplifying the pointer arithmetic involved.
For Context
The -fanalyzer is a tool that attempts to find bugs in code by reasoning about what values variables might hold during program execution, without actually running the program. This commit improves the analyzer's ability to understand pointer arithmetic, specifically pointer subtraction ((X + Y) - X). This allows the analyzer to better understand how standard library components like std::string work and find potential issues in code that uses them.