Geoffrey1014/SA_Bugs

GCC --Wdiv-by-zero false negative with `(d.b = 1) / f`

Opened this issue · 3 comments

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

void __analyzer_eval();

struct a
{
    int b : 6;
} c()
{
    struct a d;
    int e = 2;
    int f = 0;
    if ((d.b = 1) / f)
        if (1 >= d.b <= e)
        {
            __analyzer_eval(0 >= d.b <= e);
        }
}

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

GCC Static Analyzer does not generate a div-by-zero warning for the if ((d.b = 1) / f) statement, but if it is changed to if ((d.b = 1) / 0), analyzer generates that warning.

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

Input:

void __analyzer_eval();

struct a
{
    int b : 6;
} c()
{
    struct a d;
    int e = 2;
    int f = 0;
    if ((d.b = 1) / f)
        if (1 >= d.b <= e)
        {
            __analyzer_eval(0 >= d.b <= e);
        }
}