public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/108739] New: GCC Static Analyzer evaluates `a > b `to be TRUE but evaluates `b < a` to be UNKNOWN
@ 2023-02-09 8:10 geoffreydgr at icloud dot com
0 siblings, 0 replies; only message in thread
From: geoffreydgr at icloud dot com @ 2023-02-09 8:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108739
Bug ID: 108739
Summary: GCC Static Analyzer evaluates `a > b `to be TRUE but
evaluates `b < a` to be UNKNOWN
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: ---
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
```c
#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
```
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-09 8:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 8:10 [Bug analyzer/108739] New: GCC Static Analyzer evaluates `a > b `to be TRUE but evaluates `b < a` to be UNKNOWN geoffreydgr at icloud dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).