Hello,

I'm trying to add some validation checks in a function body using CIL.
To do that, I call visitCilBlock on a function body and I pass a
visitor with the
vstmt method implemented.

I get the following error when I run the code:

Bug: Visitor's instruction queue is not empty.
  You should only use queueInstr inside a function body!

I'm not sure what is going on here. I passed a function body to the
visitor, should it
then not be inside it when I call queueInstr ?

I've included a stripped down module and an example C program in attachment.

full output:

deeps...@thesismachine:~/Thesis/testcases/loop-test$ cilly
-fno-stack-protector -save-temps --dosva --noPrintLn main.c
gcc -D_GNUCC -E -save-temps -DCIL=1 main.c -o ./main.i
/home/deepstar/Thesis/downloads/cil-1.3.7/obj/x86_LINUX/cilly.asm.exe
--out ./main.cil.c --dosva --noPrintLn ./main.i
main.c:14: Warning: Body of function main falls-through. Adding a
return statement
Bug: Visitor's instruction queue is not empty.
  You should only use queueInstr inside a function body!
VSTMT: Loop() at main.c:8
Fatal error: exception Errormsg.Error

kind regards,
-- Steven
open Pretty
open Cil

class svaModifyVisitor varlist = object(self)
  inherit nopCilVisitor

  method vstmt s = 
    let verify_func = emptyFunction "someFunction" in
    let verify_exp = (Lval((Var(verify_func.svar)),NoOffset)) in
    match s.skind with
  | Loop(_,loc,_,_)     -> 
        ignore (printf "VSTMT: Loop() at %s:%i\n" loc.file loc.line); 
        self#queueInstr [Call(None,verify_exp,[],loc)];
        DoChildren;
  | _ -> DoChildren;
end

    
class svaAnalyzeVisitor f = object 
  inherit nopCilVisitor (* only look at function bodies *)
  method vglob gl = match gl with
    GFun(fundec,funloc) -> 
        let modify = new svaModifyVisitor [] in
        fundec.sbody <- visitCilBlock modify fundec.sbody ;
        ChangeTo([GFun(fundec,funloc)])
  | _ -> DoChildren
end
    
let sva (f : file)  =
  visitCilFile (new svaAnalyzeVisitor f) f;
  f

let default_sva (f : file) =
  ignore (sva f)
      
let feature1 : featureDescr = 
  { fd_name = "sva";
    fd_enabled = Cilutil.doSva;
    fd_description = "blabla";
    fd_extraopt = [];
    fd_doit = (function (f: file) -> default_sva f);
    fd_post_check = true;
  } 
int main(int argc, char **argv) {
    char buffer[80];
    char *p = argv[1];
    char *q = buffer;

    strcpy(buffer, argv[0]);

    while(argc > 0 && p && *p) {
        *q++ = *p++;
    }

    *q = 0;

    printf("%s\n", buffer);
}
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to