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

llvm-slicer says it saves sliced module but doesn't #383

Closed FerranAlet closed 3 years ago

FerranAlet commented 3 years ago

Hi,

I'm running dg/tools/dgtool llvm-slicer -c 21:C -cda ntscd hello.cpp -statistics on a simple code (pasted below). It seems to work fine, printing:

Statistics before Globals/Functions/Blocks/Instr.: 1 35 63 578
  invoke void @_ZNSt6vectorIiSaIiEEC2EmRKS0_(%"class.std::vector"* %8, i64 3, %"class.std::allocator"* dereferenceable(1) %9)
          to label %18 unwind label %34, !dbg !1272
  %19 = invoke dereferenceable(32) %"class.std::__cxx11::basic_string"* @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEpLEPKc(%"class.std::__cxx11::basic_string"* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0))
          to label %20 unwind label %38, !dbg !1280
  %45 = insertvalue { i8*, i32 } undef, i8* %43, 0, !dbg !1272
  %46 = insertvalue { i8*, i32 } %45, i32 %44, 1, !dbg !1272
  resume { i8*, i32 } %46, !dbg !1272
  %35 = landingpad { i8*, i32 }
          cleanup, !dbg !1289
  invoke void @_ZSt8_DestroyIPiiEvT_S1_RSaIT0_E(i32* %9, i32* %13, %"class.std::allocator"* dereferenceable(1) %15)
          to label %16 unwind label %18, !dbg !1263
  invoke void @_ZNSt12_Vector_baseIiSaIiEE13_M_deallocateEPim(%"struct.std::_Vector_base"* %5, i32* %8, i64 %18)
          to label %19 unwind label %21, !dbg !1051
  %22 = landingpad { i8*, i32 }
          catch i8* null, !dbg !1052
  %19 = landingpad { i8*, i32 }
          catch i8* null, !dbg !1264
  %39 = landingpad { i8*, i32 }
          cleanup, !dbg !1289
WARNING: matched due to a lack of information:   %6 = call i32 @_Z1fii(i32 %4, i32 %5), !dbg !1048
Matched line 21 with variable C to:
  %6 = call i32 @_Z1fii(i32 %4, i32 %5), !dbg !1048
Matched line 21 with variable C to:
  store i32 %6, i32* %3, align 4, !dbg !1045
[llvm-slicer] CPU time of pointer analysis: 4.024000e-03 s
[llvm-slicer] CPU time of data dependence analysis: 2.100000e-04 s
[llvm-slicer] CPU time of control dependence analysis: 1.730000e-04 s
[llvm-slicer] Finding dependent nodes took 0 sec 0 ms
[llvm-slicer] Slicing dependence graph took 0 sec 0 ms
[llvm-slicer] Sliced away 73 from 205 nodes in DG
Statistics after Globals/Functions/Blocks/Instr.: 1 7 20 141
[llvm-slicer] saving sliced module to: hello.sliced

However, there is no hello.sliced anywhere. Any ideas on how to get the file or at least get the lines from the source code that aren't sliced?

Thanks!

In case it helps; this is the code:

#include<vector>
#include<string>
using namespace std;

int f(int A, int B) {
    int D = 100;
    int E = D+100;
    int F = E-D;
    vector<int> v(3);
    string s;
    s += "hello";
    B += v[1];
    B += 1; 
    A += B - 1; 
    B += 100;
    return A; 
}

int main() {
    int A = 0, B = 1000; 
    int C = f(A,B); 
}
mchalupa commented 3 years ago

Hi,

this is probably a bug in dgtool. It works in a temporary directory and does not copy back the created files. Until this issue is resolved, you can fix it by not using dgtool (just use clang + llvm-slicer).

mchalupa commented 3 years ago

Or you can use the -o option for the slicer.

FerranAlet commented 3 years ago

Thanks @mchalupa that worked!