https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109195

            Bug ID: 109195
           Summary: GCC Static Analyzer does not know "a+0 <= b+1" in the
                    true branch of if (a <= b), but knows "a+0 < b+1".
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: geoffreydgr at icloud dot com
  Target Milestone: ---

GCC Static Analyzer does not know "a+0 <= b+1" in the true branch of if (a <=
b), but knows "a+0 < b+1".

 See it live: https://godbolt.org/z/PGhfKjjWG

Input:
```c
#include <stdint.h>
#include <stdbool.h>

int main(int a, int b, int c, int d) {
    if ((a<b)){
       // fact
        __analyzer_eval((a<=b) == true);
        __analyzer_eval((a<b || a==b) == true);

        // Add a positive number
        __analyzer_eval( a+0 <= b+0);

        __analyzer_eval( a+0 <= b+1);
        __analyzer_eval( a+0 < b+1);
        __analyzer_eval( 0 <= 1);

        __analyzer_eval( a+1 <= b+1);
        __analyzer_eval( a+0 <= b+2);
        __analyzer_eval( a+0 < b+2);
        __analyzer_eval( a+1 <= b+2);
        __analyzer_eval( a+1 < b+2);
        __analyzer_eval( a+2 <= b+2);
    }
}
```

Output:
```
<source>: In function 'main':
<source>:7:9: warning: implicit declaration of function '__analyzer_eval'
[-Wimplicit-function-declaration]
    7 |         __analyzer_eval((a<=b) == true);
      |         ^~~~~~~~~~~~~~~
<source>:7:9: warning: TRUE
    7 |         __analyzer_eval((a<=b) == true);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:8:9: warning: TRUE
    8 |         __analyzer_eval((a<b || a==b) == true);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:11:9: warning: TRUE
   11 |         __analyzer_eval( a+0 <= b+0);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:13:9: warning: UNKNOWN
   13 |         __analyzer_eval( a+0 <= b+1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:14:9: warning: TRUE
   14 |         __analyzer_eval( a+0 < b+1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:15:9: warning: TRUE
   15 |         __analyzer_eval( 0 <= 1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
<source>:17:9: warning: TRUE
   17 |         __analyzer_eval( a+1 <= b+1);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:18:9: warning: UNKNOWN
   18 |         __analyzer_eval( a+0 <= b+2);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:19:9: warning: UNKNOWN
   19 |         __analyzer_eval( a+0 < b+2);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:20:9: warning: UNKNOWN
   20 |         __analyzer_eval( a+1 <= b+2);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:21:9: warning: TRUE
   21 |         __analyzer_eval( a+1 < b+2);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:22:9: warning: TRUE
   22 |         __analyzer_eval( a+2 <= b+2);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 0
```
  • [Bug analyzer/109195] New: GCC ... geoffreydgr at icloud dot com via Gcc-bugs

Reply via email to