Open FerranAlet opened 3 years ago
Problem: The code wouldn't compile (s and v are not declared) and s isn't relevant to A.
The code generated by llvm-to-source
is not meant to be compilable. This tool just writes out the lines of the original program that are present also in the slice (or the other bitcode that is passed as the argument). The tool is for "overview", really. llvm-slicer
should produce executable LLVM bitcode, though.
Problem: lines 6,7,8 are superfluous. It's missing the #include and the using namespace (that's fine)
The superfluous lines are there because DG does not support C++ and thus it over-approximates the behavior of the program. This over-approximation leads to bigger slices.
Thanks @mchalupa for the quick response! Two follow-ups:
Thanks!
Sorry for the dumb question, but is there any other type of instruction beyond declaration that will not be picked up by llvm-to-source?
Probably yes, but hard to tell... maybe some global initialization? However, if you need a compilable C code, you can use a tool like rellic, llvm2c, or llvm-cbe to transform the sliced LLVM to C (I do not know how is it with the support of C++ in these tools).
Does the fact that C++ is not supported only result in over-approximations or the program can just fail to run as well?
In the presence of exceptions in the program or some functions that may abort inside libstdc++, the program may also fail running. In other cases, it should be just over-approximation -- but it is not tested at all.
Hi,
As far as I understand, I'm getting some miss-sliced examples. I'm unsure whether it's a bug or I'm violating a pre-condition of dg:
Example 1
Code
Command: dg/tools/dgtool llvm-slicer -Xclang -g -c 21:C -cda ntscd -annotate slice hello.cpp -statistics -dump-dg && dg/tools/llvm-to-source hello.sliced hello.cpp Result:
Problem: The code wouldn't compile (s and v are not declared) and s isn't relevant to A.
Example 2:
Code
Command dg/tools/dgtool llvm-slicer -Xclang -g -c 20:C -cda ntscd -annotate slice hello.cpp -statistics -dump-dg && dg/tools/llvm-to-source hello.sliced hello.cpp
Result
Problem: lines 6,7,8 are superfluous. It's missing the #include and the using namespace (that's fine)
If I'm doing something wrong or running into problems with dg, is there a work-around? Thanks!