I've been using CIL to do some instrumentations and discovered this
unexpected bug --
let's say I want to add a statement s1 (e.g., printf("hello world");)
before every IF in the code. I created an instrumenter with CIL that
basically does mkStmt(Block(mkBlock([s1 ; if_stuff]))) .
It works out well in most case except the below :
switch (something){
case something1:
if(cond1){ ... }
break;
if(cond2){ ... }
break;
}
applying the instrumenter gives this result
switch (something){
s1;
case something1:
if(cond1){ }
break;
s1;
case something2:
if(cond2){
}
break;
}
instead of
switch (something){
case something1:
s1;
if(cond1){
}
break;
case something2:
s2;
if(cond2){
}
break;
}
Thus, the new statements (s1,s2 ..) added always go above the "case ... "
instead of after and basically a semantic change ?
I am attaching my CIL ML code and 2 C files (t.c is the original code and
t1.c is the instrumented one)--- All are very short.
Is this a bug in CIL or there's some other way to do what I want ? TIA
VN -
open Printf
open Cil
class instrumenter () = object
inherit nopCilVisitor
method vstmt s = ChangeDoChildrenPost(
s,fun s -> (
match s.skind with
|If(_,_,_,_) -> ( (*add a hello world before if*)
let fprintf = Lval((Var (makeVarinfo true "fprintf" (TVoid []))), NoOffset) in
let hello_str = Const(CStr("hello word ")) in
let instr = Call(None,fprintf,[hello_str],!currentLoc) in
let ns = mkStmtOneInstr(instr) in
mkStmt(Block(mkBlock([ns;s])))
)
|_ -> s (*don't change*)
)
)
end
let _ =
let filename = Sys.argv.(1) in
initCIL();
let file = Frontc.parse filename () in
visitCilFileSameGlobals (new instrumenter()) file;
iterGlobals file (
fun glob ->
dumpGlobal defaultCilPrinter stdout glob ;
) ;
exit 0
int main(){
int choice = 1;
int printme = 0;
switch (choice){
case 0: if(printme) printf("one\n"); break;
case 1: if(printme) printf("two\n"); break;
}
return 0;
}
/* compiler builtin:
void __builtin_varargs_start(__builtin_va_list ) ; */
/* compiler builtin:
int __builtin_strcmp(char const * , char const * ) ; */
/* compiler builtin:
void *__builtin___memmove_chk(void * , void const * , unsigned long ,
unsigned long ) ; */
/* compiler builtin:
char *__builtin_strpbrk(char const * , char const * ) ; */
/* compiler builtin:
void *__builtin_memcpy(void * , void const * , unsigned long ) ; */
/* compiler builtin:
double __builtin_exp(double ) ; */
/* compiler builtin:
long double __builtin_nanl(char const * ) ; */
/* compiler builtin:
double __builtin_cos(double ) ; */
/* compiler builtin:
char *__builtin_strchr(char * , int ) ; */
/* compiler builtin:
float __builtin_atan2f(float , float ) ; */
/* compiler builtin:
void *__builtin___memcpy_chk(void * , void const * , unsigned long ,
unsigned long ) ; */
/* compiler builtin:
double __builtin_asin(double ) ; */
/* compiler builtin:
int __builtin_ctz(unsigned int ) ; */
/* compiler builtin:
char *__builtin_stpcpy(char * , char const * ) ; */
/* compiler builtin:
float __attribute__((____vector_size____(16))) __builtin_ia32_unpckhps(float __attribute__((____vector_size____(16))) ,
float __attribute__((____vector_size____(16))) ) ; */
/* compiler builtin:
double __builtin_nans(char const * ) ; */
/* compiler builtin:
long double __builtin_atan2l(long double , long double ) ; */
/* compiler builtin:
float __builtin_logf(float ) ; */
/* compiler builtin:
int __builtin___fprintf_chk(void * , int , char const * , ...) ; */
/* compiler builtin:
int __builtin___vsprintf_chk(char * , int , unsigned long ,
char const * , __builtin_va_list ) ; */
/* compiler builtin:
char *__builtin___strncpy_chk(char * , char const * , unsigned long ,
unsigned long ) ; */
/* compiler builtin:
float __attribute__((____vector_size____(16))) __builtin_ia32_subps(float __attribute__((____vector_size____(16))) ,
float __attribute__((____vector_size____(16))) ) ; */
/* compiler builtin:
float __builtin_log10f(float ) ; */
/* compiler builtin:
double __builtin_atan(double ) ; */
/* compiler builtin:
void *__builtin_alloca(unsigned long ) ; */
/* compiler builtin:
void __builtin_va_end(__builtin_va_list ) ; */
/* compiler builtin:
int __builtin_strncmp(char const * , char const * , unsigned long ) ; */
/* compiler builtin:
double __builtin_sin(double ) ; */
/* compiler builtin:
long double __builtin_logl(long double ) ; */
/* compiler builtin:
float __builtin_coshf(float ) ; */
/* compiler builtin:
void *__builtin___mempcpy_chk(void * , void const * , unsigned long ,
unsigned long ) ; */
/* compiler builtin:
char *__builtin___strcat_chk(char * , char const * , unsigned long ) ; */
/* compiler builtin:
float __builtin_nansf(char const * ) ; */
/* compiler builtin:
void *__builtin_memset(void * , int , int ) ; */
/* compiler builtin:
void __builtin_va_copy(__builtin_va_list , __builtin_va_list ) ; */
/* compiler builtin:
float __builtin_sinhf(float ) ; */
/* compiler builtin:
long double __builtin_log10l(long double ) ; */
/* compiler builtin:
long double __builtin_coshl(long double ) ; */
/* compiler builtin:
unsigned long __builtin_strlen(char const * ) ; */
/* compiler builtin:
int __builtin_ffs(unsigned int ) ; */
/* compiler builtin:
float __builtin_asinf(float ) ; */
/* compiler builtin:
long double __builtin_nansl(char const * ) ; */
/* compiler builtin:
double __builtin_frexp(double , int * ) ; */
/* compiler builtin:
double __builtin_tan(double ) ; */
/* compiler builtin:
long double __builtin_sinhl(long double ) ; */
/* compiler builtin:
float __builtin_frexpf(float , int * ) ; */
/* compiler builtin:
long double __builtin_asinl(long double ) ; */
/* compiler builtin:
void *__builtin_frame_address(unsigned int ) ; */
/* compiler builtin:
double __builtin_floor(double ) ; */
/* compiler builtin:
float __builtin_tanhf(float ) ; */
/* compiler builtin:
int __builtin_parityl(unsigned long ) ; */
/* compiler builtin:
int __builtin_clzl(unsigned long ) ; */
/* compiler builtin:
double __builtin_powi(double , int ) ; */
/* compiler builtin:
long double __builtin_frexpl(long double , int * ) ; */
/* compiler builtin:
float __builtin_atanf(float ) ; */
/* compiler builtin:
float __builtin_huge_valf(void) ; */
/* compiler builtin:
float __builtin_sqrtf(float ) ; */
/* compiler builtin:
float __builtin_fmodf(float ) ; */
/* compiler builtin:
unsigned long __builtin_object_size(void * , int ) ; */
/* compiler builtin:
void __builtin_va_arg(__builtin_va_list , unsigned long , void * ) ; */
/* compiler builtin:
void __builtin_stdarg_start(__builtin_va_list ) ; */
/* compiler builtin:
float __attribute__((____vector_size____(16))) __builtin_ia32_mulps(float __attribute__((____vector_size____(16))) ,
float __attribute__((____vector_size____(16))) ) ; */
/* compiler builtin:
long double __builtin_tanhl(long double ) ; */
/* compiler builtin:
double __builtin_nan(char const * ) ; */
/* compiler builtin:
void __builtin_return(void const * ) ; */
/* compiler builtin:
long double __builtin_atanl(long double ) ; */
/* compiler builtin:
long double __builtin_huge_vall(void) ; */
/* compiler builtin:
float __builtin_inff(void) ; */
/* compiler builtin:
long double __builtin_sqrtl(long double ) ; */
/* compiler builtin:
long double __builtin_fmodl(long double ) ; */
/* compiler builtin:
int __builtin___printf_chk(int , char const * , ...) ; */
/* compiler builtin:
float __builtin_floorf(float ) ; */
/* compiler builtin:
float __builtin_fabsf(float ) ; */
/* compiler builtin:
int __builtin_popcountll(unsigned long long ) ; */
/* compiler builtin:
int __builtin___sprintf_chk(char * , int , unsigned long , char const *
, ...) ; */
/* compiler builtin:
int __builtin___vprintf_chk(int , char const * , __builtin_va_list ) ; */
/* compiler builtin:
float __attribute__((____vector_size____(16))) __builtin_ia32_maxps(float __attribute__((____vector_size____(16))) ,
float __attribute__((____vector_size____(16))) ) ; */
/* compiler builtin:
int __builtin___snprintf_chk(char * , unsigned long , int ,
unsigned long , char const * , ...) ; */
/* compiler builtin:
long double __builtin_infl(void) ; */
/* compiler builtin:
void *__builtin_mempcpy(void * , void const * , unsigned long ) ; */
/* compiler builtin:
long double __builtin_floorl(long double ) ; */
/* compiler builtin:
int __builtin_ctzl(unsigned long ) ; */
/* compiler builtin:
long double __builtin_fabsl(long double ) ; */
/* compiler builtin:
int __builtin_clz(unsigned int ) ; */
/* compiler builtin:
double __builtin_fabs(double ) ; */
/* compiler builtin:
int __builtin_popcount(unsigned int ) ; */
/* compiler builtin:
void __builtin_bcopy(void const * , void * , unsigned long ) ; */
/* compiler builtin:
double __builtin_ceil(double ) ; */
/* compiler builtin:
double __builtin_ldexp(double , int ) ; */
/* compiler builtin:
float __builtin_sinf(float ) ; */
/* compiler builtin:
float __builtin_acosf(float ) ; */
/* compiler builtin:
int __builtin___vsnprintf_chk(char * , unsigned long , int ,
unsigned long , char const * ,
__builtin_va_list ) ; */
/* compiler builtin:
double __builtin_sinh(double ) ; */
/* compiler builtin:
int __builtin_ffsll(unsigned long long ) ; */
/* compiler builtin:
char *__builtin___strcpy_chk(char * , char const * , unsigned long ) ; */
/* compiler builtin:
double __builtin_inf(void) ; */
/* compiler builtin:
void __builtin_prefetch(void const * , ...) ; */
/* compiler builtin:
long double __builtin_sinl(long double ) ; */
/* compiler builtin:
long double __builtin_acosl(long double ) ; */
/* compiler builtin:
double __builtin_sqrt(double ) ; */
/* compiler builtin:
double __builtin_fmod(double ) ; */
/* compiler builtin:
char *__builtin_strcpy(char * , char const * ) ; */
/* compiler builtin:
float __builtin_ceilf(float ) ; */
/* compiler builtin:
void *__builtin_return_address(unsigned int ) ; */
/* compiler builtin:
char *__builtin___stpcpy_chk(char * , char const * , unsigned long ) ; */
/* compiler builtin:
float __builtin_tanf(float ) ; */
/* compiler builtin:
int __builtin_parityll(unsigned long long ) ; */
/* compiler builtin:
float __builtin_ldexpf(float , int ) ; */
/* compiler builtin:
int __builtin_types_compatible_p(unsigned long , unsigned long ) ; */
/* compiler builtin:
double __builtin_log10(double ) ; */
/* compiler builtin:
float __builtin_expf(float ) ; */
/* compiler builtin:
int __builtin_clzll(unsigned long long ) ; */
/* compiler builtin:
float __attribute__((____vector_size____(16))) __builtin_ia32_unpcklps(float __attribute__((____vector_size____(16))) ,
float __attribute__((____vector_size____(16))) ) ; */
/* compiler builtin:
double __builtin_tanh(double ) ; */
/* compiler builtin:
int __builtin_constant_p(int ) ; */
/* compiler builtin:
long double __builtin_ceill(long double ) ; */
/* compiler builtin:
int __builtin_va_arg_pack_len(void) ; */
/* compiler builtin:
void *__builtin_apply(void (*)() , void * , unsigned long ) ; */
/* compiler builtin:
long double __builtin_tanl(long double ) ; */
/* compiler builtin:
double __builtin_log(double ) ; */
/* compiler builtin:
long double __builtin_ldexpl(long double , int ) ; */
/* compiler builtin:
int __builtin_popcountl(unsigned long ) ; */
/* compiler builtin:
long double __builtin_expl(long double ) ; */
/* compiler builtin:
void *__builtin___memset_chk(void * , int , unsigned long , unsigned long ) ; */
/* compiler builtin:
char *__builtin___strncat_chk(char * , char const * , unsigned long ,
unsigned long ) ; */
/* compiler builtin:
double __builtin_huge_val(void) ; */
/* compiler builtin:
__builtin_va_list __builtin_next_arg(void) ; */
/* compiler builtin:
void *__builtin_apply_args(void) ; */
/* compiler builtin:
float __builtin_powif(float , int ) ; */
/* compiler builtin:
int __builtin___vfprintf_chk(void * , int , char const * ,
__builtin_va_list ) ; */
/* compiler builtin:
float __builtin_modff(float , float * ) ; */
/* compiler builtin:
double __builtin_atan2(double , double ) ; */
/* compiler builtin:
char *__builtin_strncpy(char * , char const * , unsigned long ) ; */
/* compiler builtin:
long double __builtin_powil(long double , int ) ; */
/* compiler builtin:
float __builtin_cosf(float ) ; */
/* compiler builtin:
void __builtin_bzero(void * , unsigned long ) ; */
/* compiler builtin:
unsigned long __builtin_strspn(char const * , char const * ) ; */
/* compiler builtin:
long double __builtin_modfl(long double , long double * ) ; */
/* compiler builtin:
int __builtin_parity(unsigned int ) ; */
/* compiler builtin:
double __builtin_cosh(double ) ; */
/* compiler builtin:
char *__builtin_strncat(char * , char const * , unsigned long ) ; */
/* compiler builtin:
long __builtin_expect(long , long ) ; */
/* compiler builtin:
double __builtin_acos(double ) ; */
/* compiler builtin:
int __builtin_va_arg_pack(void) ; */
/* compiler builtin:
float __attribute__((____vector_size____(16))) __builtin_ia32_addps(float __attribute__((____vector_size____(16))) ,
float __attribute__((____vector_size____(16))) ) ; */
/* compiler builtin:
long double __builtin_cosl(long double ) ; */
/* compiler builtin:
void __builtin_va_start(__builtin_va_list ) ; */
/* compiler builtin:
int __builtin_ctzll(unsigned long long ) ; */
/* compiler builtin:
unsigned long __builtin_strcspn(char const * , char const * ) ; */
/* compiler builtin:
int __builtin_ffsl(unsigned long ) ; */
/* compiler builtin:
float __builtin_nanf(char const * ) ; */
#line 5 "t.c"
extern int ( /* missing proto */ printf)() ;
#line 1 "t.c"
int main(void)
{ int choice ;
int printme ;
{
#line 2
choice = 1;
#line 3
printme = 0;
#line 4
switch (choice) {
{
#line 5
fprintf("hello word ");
case 0:
#line 5
if (printme) {
#line 5
printf("one\n");
}
}
#line 5
break;
{
#line 6
fprintf("hello word ");
case 1:
#line 6
if (printme) {
#line 6
printf("two\n");
}
}
#line 6
break;
}
#line 10
return (0);
}
}
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users