mchalupa / dg

[LLVM Static Slicer] Various program analyses, construction of dependence graphs and program slicing of LLVM bitcode.
MIT License
474 stars 131 forks source link

`ret` and Line number as a slicing criteria isn't working #415

Open aagontuk opened 2 years ago

aagontuk commented 2 years ago

I am trying to slice following example (Adding line number for convenience):

     1  #include <stdio.h>
     2
     3  int main(int argc, char *argv[]) {
     4      int x = 10, y = 20, z = 30;
     5
     6      z = x + 10;
     7      z = z + 1;
     8
     9      y = 50;
    10
    11      return z;
    12  }

I am trying to slice on return statement in following way:

$ clang -g -c -emit-llvm example.c
$ ./llvm-slicer -c ret example.bc

llvm-slicer is giving following output:

No reachable slicing criteria: '' 'ret'
[llvm-slicer] saving sliced module to: example.sliced

I am getting same output when I try to slice using line numbers. If I give -c 7:z I am getting following output:

No reachable slicing criteria: '' '7:z'
[llvm-slicer] saving sliced module to: example.sliced

But if I use a function call site as a slicing criteria it is generating correct slice. Both -c foo and -c 7:z is working, given that foo is called in line 7 passing z as parameter.

mchalupa commented 2 years ago

This looks like a bug, thaks for reporting it.

For both -c 7:z and -sc 7#z the criteria get parsed correctly, so the problem will be in their matching:

$ tools/llvm-slicer -c '7:z' t.bc -dbg
[39710][llvm - slicer] Searching for slicing criteria values
[39883][llvm - slicer] Criterion file # fun # line # obj ==>  #  # 7 # z
[39907][llvm - slicer] Checking global variables for slicing criteria
[39925][llvm - slicer] Checking all instructions for slicing criteria
No reachable slicing criteria: '' '7:z'
[llvm-slicer] saving sliced module to: t.sliced