Frama-C Bug Tracking System - Frama-C
View Issue Details
0000325Frama-CPlug-in > Evapublic2009-11-07 12:052014-02-12 16:55
pascal 
pascal 
normalfeaturealways
closedfixed 
Frama-C Beryllium-20090902 
Frama-C Boron-20100401 
0000325: Precise widening when a loop condition involves a char or short

> Depending the type of i, the range is not the same.
> The range of i in the loop is [0..10] (for int) or [0..15] for char or
> short.
_____

void main(void)
{
char i=0;
int j=0;
while (i<10) i++;
while (j<10) j++;
}

[value] ====== VALUES COMPUTED ======
[value] Values for function main:
i IN {10; 11; 12; 13; 14; 15; }
j IN {10; }
_____

Note that the AST for the two loops is different:
  i = (char)0;
  j = 0;
  while ((int )i < 10) {i = (char )((int )i + 1);}
  while (j < 10) {j ++;}

CIL transforms the code thus because the standard
specifies that operators such as ++ do not operate on
types smaller than int, and that values of these types
are implicitly promoted to int in these conditions.

Meanwhile, in the absence of any loop-related
option, the value analysis tries to keep computations
short at the price of precision by using a technique
called "widening". In order to limit the loss of precision,
however, various heuristics are used, including a
syntactic one for the j loop that recognizes that
j IN [0..10] is a good candidate for the loop invariant.

These heuristic does not currently recognize the condition
((int )i < 10) as one where it would be valuable to try
the same kind of invariant.

No tags attached.
has duplicate 0000414closed pascal imprecision in widening/narrowing for char and short index 
Issue History
2009-11-07 12:05pascalNew Issue
2009-11-07 12:05pascalStatusnew => assigned
2009-11-07 12:05pascalAssigned To => pascal
2010-02-19 14:46pascalRelationship addedhas duplicate 0000414
2010-02-19 16:09svnCheckin
2010-02-19 16:09svnStatusassigned => resolved
2010-02-19 16:09svnResolutionopen => fixed
2010-04-13 15:30signolesStatusresolved => new
2010-04-13 15:31signolesStatusnew => closed
2010-04-13 15:33signolesFixed in Version => Frama-C Boron
2018-01-12 14:26signolesCategoryPlug-in > value analysis => Plug-in > Eva

There are no notes attached to this issue.