Skip to content

Incorrect slices #31

Open
Open

Description

@archived-c

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.slice

Activity

  1. archived-c commented on Oct 12, 2020

    @archived-c
    Author

    Okay so, after building srcSlice from master, the slice might still be slightly incorrect on the above example:

    ==========================================================================
    Name and type: n 
    Contains Declaration: 1 Containing class: 
    Dvars: {}
    Aliases: {}
    Cfunctions: {printf 2,bar 1,foo 1,}
    Use: {4,12,}
    Def: {1,7,17,}
    Control Edges: {(0, 17),}
    ==========================================================================
    ==========================================================================
    Name and type: v 
    Contains Declaration: 1 Containing class: 
    Dvars: {}
    Aliases: {}
    Cfunctions: {printf 3,bar 2,}
    Use: {4,10,12,}
    Def: {1,8,}
    Control Edges: {(8, 10),(8, 12),(10, 12),}
    ==========================================================================
    ==========================================================================
    Name and type: x 
    Contains Declaration: 1 Containing class: 
    Dvars: {}
    Aliases: {}
    Cfunctions: {printf 2,bar 1,}
    Use: {4,12,}
    Def: {1,7,}
    Control Edges: {(7, 12),}
    ==========================================================================
    ==========================================================================
    Name and type: b 
    Contains Declaration: 1 Containing class: 
    Dvars: {}
    Aliases: {}
    Cfunctions: {printf 3,}
    Use: {4,}
    Def: {1,}
    Control Edges: {(1, 4),}
    ==========================================================================
    ==========================================================================
    Name and type: a 
    Contains Declaration: 1 Containing class: 
    Dvars: {}
    Aliases: {}
    Cfunctions: {printf 2,}
    Use: {4,}
    Def: {1,}
    Control Edges: {(1, 4),}
    ==========================================================================
    

    I expected variable n to be used on lines 2, 4, 9, 12, 18.
    I expected variable v to be used on lines 3, 4, 10, 12.
    I expected variable x to be used on lines 2, 4, 9, 12.
    I expected variable b to be used on lines 3, 4.
    I expected variable a to be used on lines 2, 4.

    These are still better than the results from my original post, but what I got was still slightly different than what I expected. Please let me know if I'm interpreting this incorrectly.

    Thanks

  2. cnewman commented on Jan 8, 2021

    @cnewman
    Member

    Yes, there have been several updates to srcML which may affect the quality of srcSlice output, beside the known bugs that already existed. The tool needs maintenance and I have very little time to give it the attention it needs.

    I will be working on it some in the last couple weeks before the semester begins again. We will see how much I am able to complete.

  3. archived-c commented on Jan 11, 2021

    @archived-c
    Author

    Understandable, thanks for the reply.

    If there are any specific issues or features of srcSlice that you can elaborate on, I would be happy to take a look and submit pull requests where I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions