Geoffrey1014 / SA_Bugs

record bugs of static analyzers
1 stars 1 forks source link

GCC Static Analyzer evaluates `(((a())>=(0))&&((a())!=(0)))==false` to be FALSE with the fact `a() <= 0` and `a()` return int #37

Closed Geoffrey1014 closed 1 year ago

Geoffrey1014 commented 1 year ago

date: 2023-1-10 commit: 8c8ca873216387bc26046615c806b96f0345ff9d args: -O0 -fanalyzer test:

#include "stdint.h"
#include <stdbool.h>
int a(); 

uint16_t b() {
  for (;;)
    if (a() <= 0) {
      __analyzer_eval((a() <= 0)==true);
      __analyzer_eval((((a())>=(0))&&((a())!=(0)))==false);

    }
}

report: fix: original:

Geoffrey1014 commented 1 year ago

https://godbolt.org/z/13qs345fY <source>:9:7 should not be reported warning: FALSE, but only warning: UNKNOWN.

Output:

<source>: In function 'b':
<source>:8:7: warning: implicit declaration of function '__analyzer_eval' [-Wimplicit-function-declaration]
    8 |       __analyzer_eval((a() <= 0)==true);
      |       ^~~~~~~~~~~~~~~
<source>:8:7: warning: UNKNOWN
    8 |       __analyzer_eval((a() <= 0)==true);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:9:7: warning: FALSE
    9 |       __analyzer_eval((((a())>=(0))&&((a())!=(0)))==false);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:9:7: warning: UNKNOWN
Compiler returned: 0
Geoffrey1014 commented 1 year ago

called_unknown_fn

image