--- layout: fc_discuss_archives title: Message 2 from Frama-C-discuss on April 2017 ---
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Frama-c-discuss] Value analysis: resulting intervals after loop



Dear all,
we have a particular scenario where we are unable to explain the results
reported by Frama-C. Any pointers would be greatly appreciated.

We are analyzing the sun newlib math library (
ftp://sourceware.org/pub/newlib/newlib-2.4.0.tar.gz) from where we have
extracted the following snippet:

#include <stdint.h>

typedef union {
    float value;
    int32_t word;
} ieee_float_shape_type;

void main(float x) {
    int32_t hx;
    ieee_float_shape_type temp_u;

    temp_u.value = x;
    hx = temp_u.word;
    hx &= 0x7FFFFFFF;

    int i, ix;

    if (hx < 0x0080000L) {
        ix = -126;
        Frama_C_show_each_ix_before(ix);
        i = hx << 8;
        while (i > 0) {
            ix --;
            Frama_C_show_each_ix_loop(ix);
            i <<= 1;
        }
    }
    else {
        ix = (hx >> 23) - 127;
        Frama_C_show_each_ix_else(ix);
    }
    Frama_C_show_each_ix_after(ix);
}

we are interested in the possible values of variable 'ix' at the end of the
function.

Running value analysis with a sufficiently large slevel (30 for example)
outputs:

[value] Called Frama_C_show_each_ix_before({-126})
[value] Called Frama_C_show_each_ix_else([-127..128])
[value] Called Frama_C_show_each_ix_loop({-127})
[value] Called Frama_C_show_each_ix_loop({-128})
[value] Called Frama_C_show_each_ix_loop({-129})
[value] Called Frama_C_show_each_ix_loop({-130})
[value] Called Frama_C_show_each_ix_loop({-131})
(...)
[value] Called Frama_C_show_each_ix_loop({-132})
[value] Called Frama_C_show_each_ix_loop({-133})
[value] Called Frama_C_show_each_ix_loop({-134})
[value] Called Frama_C_show_each_ix_loop({-135})
[value] Called Frama_C_show_each_ix_loop({-136})
[value] Called Frama_C_show_each_ix_loop({-137})
[value] Called Frama_C_show_each_ix_loop({-138})
[value] Called Frama_C_show_each_ix_loop({-139})
[value] Called Frama_C_show_each_ix_loop({-140})
[value] Called Frama_C_show_each_ix_loop({-141})
[value] Called Frama_C_show_each_ix_loop({-142})
[value] Called Frama_C_show_each_ix_loop({-143})
[value] Called Frama_C_show_each_ix_loop({-144})
[value] Called Frama_C_show_each_ix_loop({-145})
[value] Called Frama_C_show_each_ix_loop({-146})
[value] Called Frama_C_show_each_ix_loop({-147})
[value] Called Frama_C_show_each_ix_loop({-148})
[value] Called Frama_C_show_each_ix_loop({-149})
[value] Called Frama_C_show_each_ix_after([-127..128])
[value] Called Frama_C_show_each_ix_after({-126})
[value] Recording results for main
[value] done for function main
[value] ====== VALUES COMPUTED ======
[value] Values at end of function main:
  hx ∈ [0..2147483647]
  temp_u{.value; .word} ∈ [-3.40282346639e+38 .. 3.40282346639e+38]
  i ∈ {0} or UNINITIALIZED
  ix ∈ [-127..128]

Observing the if branch, that is, the 'before' and 'loop' values for ix,
one would expect that the corresponding 'after' value is the interval
[-149,-126]. However, it is reported to be only {-126}.

The result for the else branch is correctly reported as [-127..128] and
thus, the resulting values of ix at the end of the function are reported as
[-127..128], where the expected values would be [-149,128].

The consequences of this issue are incorrect reports of dead code in the
library we are analyzing.

Again, we would greatly appreciate any pointers to what could be happening
in this case.

Best regards,
-- Sergio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gforge.inria.fr/pipermail/frama-c-discuss/attachments/20170406/01ea3804/attachment.html>