Geoffrey1014/SA_Bugs

GSA evaluates `a > b` to be TRUE but evaluates `b < a` to be UNKNOWN

Opened this issue · 2 comments

date: 2023-2-9
commit:
args: -O0 --fanalyzer
test:

#include "stdint.h"
#include "stdio.h"
#include <stdbool.h>
extern void __analyzer_describe ();
extern void __analyzer_eval ();
extern void __analyzer_dump ();
extern void __analyzer_dump_state (const char *name, ...);
extern void __analyzer_dump_region_model ();

void foo (size_t size)
{
  size_t a = size + 2;
  size_t b = size + 1;
  __analyzer_dump ();
  if(a > b){
    __analyzer_dump ();
    __analyzer_eval (a > b);
    __analyzer_eval (b < a);
    __analyzer_eval (b > a);
  }
 
}

report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108739
fix:
original:

Hi, David. I found a problem that GSA evaluates a > b to be TRUE but evaluates b < a to be UNKNOWN. I think that in the True branch of if(a>b) there should exist a constraint, and then GSA can evaluates b < a to be FALSE.
Compiling the following test case with gcc (trunk) with options "-fanalyzer ".
https://godbolt.org/z/7EWreG66W
Input

#include "stdint.h"
#include "stdio.h"
#include <stdbool.h>
extern void __analyzer_describe ();
extern void __analyzer_eval ();
extern void __analyzer_dump ();
extern void __analyzer_dump_state (const char *name, ...);
extern void __analyzer_dump_region_model ();

void foo (size_t size)
{
  size_t a = size + 2;
  size_t b = size + 1;
  __analyzer_dump ();
  if(a > b){
    __analyzer_dump ();
    __analyzer_eval (a > b);
    __analyzer_eval (b < a);
    __analyzer_eval (b > a);
  }
 
}

Output:

rmodel:
stack depth: 1
  frame (index 0): frame: 'foo'@1
clusters within frame: 'foo'@1
  cluster for: a_9: (INIT_VAL(size_8(D))+(size_t)2)
  cluster for: b_10: (INIT_VAL(size_8(D))+(size_t)1)
m_called_unknown_fn: FALSE
constraint_manager:
  equiv classes:
  constraints:
rmodel:
stack depth: 1
  frame (index 0): frame: 'foo'@1
clusters within frame: 'foo'@1
  cluster for: a_9: (INIT_VAL(size_8(D))+(size_t)2)
  cluster for: b_10: (INIT_VAL(size_8(D))+(size_t)1)
m_called_unknown_fn: FALSE
constraint_manager:
  equiv classes:
  constraints:
<source>: In function 'foo':
<source>:17:5: warning: TRUE
   17 |     __analyzer_eval (a > b);
      |     ^~~~~~~~~~~~~~~~~~~~~~~
<source>:18:5: warning: UNKNOWN
   18 |     __analyzer_eval (b < a);
      |     ^~~~~~~~~~~~~~~~~~~~~~~
<source>:19:5: warning: UNKNOWN
   19 |     __analyzer_eval (b > a);
      |     ^~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 0