-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Produces incorrect slices given the following source code (line numbers included for clarity):
1 void bar(int a, int b) {
2 if (a != 0) return;
3 if (b == 42) return;
4 printf("%d %d\n", a, b);
5 }
6
7 int foo(int x) {
8 int v = 0;
9 for (int i = 0; i < x; ++i) {
10 v++;
11 }
12 bar(x, v);
13 return 0;
14 }
15
16 int main() {
17 int n = 3;
18 return foo(n);
19 }
Produces the following srcSlice output:
1 example.cpp,main,n,def{17},use{18},dvars{},pointers{},cfuncs{}
2 example.cpp,bar,b,def{1},use{3,4},dvars{},pointers{},cfuncs{printf{3}}
3 example.cpp,bar,a,def{1},use{2,4},dvars{},pointers{},cfuncs{printf{2}}
4 example.cpp,foo,i,def{9},use{9},dvars{},pointers{},cfuncs{}
5 example.cpp,foo,v,def{8},use{1,2,4,10,12},dvars{},pointers{},cfuncs{printf{2},bar{2}}
6 example.cpp,foo,x,def{7},use{9,12},dvars{},pointers{},cfuncs{bar{1}}
In the first line of the srcSlice output, n is correctly defined and used. However, I also expected n to appear in cfuncs{foo(1)}. Additionally, variable v is incorrectly stated to be used on lines 2 & 4 which appears to actually be where variable x should be used.
Is this the expected output? If not, is this resolved when building most recent version from source?
To be clear, I downloaded prebuilt srcML from https://www.srcml.org/#download and prebuilt srcSlice from https://www.srcml.org/tools.html
To produce the above, I used the following commands:
$ srcml example.cpp --position -o example.xml
$ srcslice example.xml > example.slice
$ cat -n example.sliceMetadata
Metadata
Assignees
Labels
No labels