forked from cil-project/cil
-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
While looking into goblint/analyzer#1794, I was surprised to find that CIL silently truncates too large integer constants on attribute-less types:
int main( void ) {
volatile int a = 121111111111111; // Goblint sees (int volatile)121111111111111
int b = 121111111111111; // Goblint just sees 1623298503
return 0;
}After lots of digging, this seems to be done here by kintegerCilint:
Lines 6100 to 6113 in a35d59e
| let mkCastT ~(e: exp) ~(oldt: typ) ~(newt: typ) = | |
| (* Do not remove old casts because they are conversions !!! *) | |
| if Util.equals (typeSig oldt) (typeSig newt) then begin | |
| e | |
| end else begin | |
| (* Watch out for constants *) | |
| match newt, e with | |
| (* Casts to _Bool are special: they behave like "!= 0" ISO C99 6.3.1.2 *) | |
| TInt(IBool, []), Const(CInt(i, _, _)) -> | |
| let v = if compare i zero_cilint = 0 then zero_cilint else one_cilint in | |
| Const (CInt(v, IBool, None)) | |
| | TInt(newik, []), Const(CInt(i, _, _)) -> kintegerCilint newik i | |
| | _ -> CastE(newt,e) | |
| end |
It seems weird, especially to do it silently while arbitrarily depending on the presence of attributes. It prevents Goblint from soundly reporting overflows on constants.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels