Analyzer follows macro aliases for named constants
Analyzer now correctly handles macro aliases for named constants, fixing test failures.
The static analyzer can now follow macro aliases when evaluating named constants. This change improves the analyzer’s ability to detect redundant flags by allowing it to resolve constants defined through macros like O_CREAT _FCREAT, which are used in libc implementations. This fix resolves several test failures related to macro aliasing.
In Details
The analyzer's redundant flag detection in r17-177-g9a5f89005dc49d required named constants to resolve to numerical values. This commit extends that capability to handle macro aliases, such as O_CREAT being an alias for _FCREAT. A depth limit for alias resolution is configurable via analyzer-max-macro-alias-depth. This addresses issues in mkostemp and mkostemps test cases.
- static analyzer
- A tool within the compiler that analyzes code without executing it to find potential errors, such as logic flaws or memory leaks. It operates on an intermediate representation of the code.
- macro alias
- A macro definition that simply renames another macro or a constant value. For example,
#define NEW_NAME OLD_NAME. - named constant
- A symbolic name given to a fixed value, typically defined using
#definein C/C++ orconst. - libc
- The standard C library, providing fundamental functions for input/output, memory management, string manipulation, and more. Examples include glibc, newlib, and picolibc.
- ODR
- One Definition Rule. A C++ rule stating that non-inline functions and variables must have exactly one definition in the program.