From: Matt H. <ma...@cs...> - 2006-11-03 18:48:26
|
Moritz Jodeit wrote: >Hi all, > >I ran across some code, which falsely generates a warning using CIL. >The following code snippet demonstrates it: > >1 #include <stdio.h> >2 #include <stdlib.h> >3 >4 int main(void) { >5 char *p; >6 int i; >7 >8 p = malloc(2*sizeof(int)); >9 *(int *)p = 1; >10 *((int *)p + 1) = 2; >11 >12 i = *((int *)p)++; >13 printf("%d\n", i); >14 i = *((int *)p)++; >15 printf("%d\n", i); >16 >17 return 0; >18 } > >Line 12 and 14 are transformed to: > >... >#line 12 > tmp = (int *)p; >#line 12 > p = (int *)p + 1; >#line 12 > i = *tmp; >... > >GCC justifiably generates a warning for the "p = (int *)p + 1" construct. >CIL should probably add the missing cast to (char *), so that it >transforms to the following construct: > > p = (char *)((int *)p + 1) > >What do you think? > >Moritz > Hi Moritz, You are right. Here is a patch: Thanks, Matt --- src/frontc/cabs2cil.ml (revision 8636) +++ src/frontc/cabs2cil.ml (working copy) @@ -3621,7 +3621,7 @@ se, e' in finishExp - (se' +++ (Set(lv, makeCastT opresult tresult t, + (se' +++ (Set(lv, makeCastT opresult tresult (typeOfLval lv), !currentLoc))) result tresult (* Should this be t instead ??? *) |