I was recently introduced to the MIT "STACK" code analyzer[1]. STACK analyses
the intermediate representation of LLVM-compiled code, and attempts to detect
cases where the compiler may optimise some code unexpectedly, usually due to
undefined behaviour. This series addresses the issues found by this tool,
outside the testsuite.

One example is the "anti-simplify" test. With code like the following:

void foo(int *x)
{
    printf("%d\n", *x);
    if (!x) {
        printf("x is evaluated to false!\n");
    }
}

The first printf() statement dereferences 'x'. At this point, either this call
succeeds, or the program will crash (Segmentation Fault). As such, subsequent
checks against 'x' must succeed. One could replace "if (!x)" with "if (false)"
and not change the behaviour of the program. The compiler may now entirely
remove the if block as an optimization. In practice, examples are likely to be
more complicated than this, but this kind of bug was found in a couple of
places within Open vSwitch.

In practice, to get up and running, the INSTALL and README files are fairly
clear. One needs to download LLVM and compile from scratch, so make sure you
have as much as 15GB free space. Once LLVM and STACK are compiled and set up
in your path, it's as easy as:

$ stack-build ./configure
$ stack-build make

This generates various *.ll and *.ll.out files within the build directory.
To analyze these files:

$ poptck
$ less pstack.txt

I didn't notice any difference to the compile time for the OVS codebase -
~3m30s with a single core. Analysis took just shy of 1m. The README has some
tips on interpreting the output. After pinpointing a particular problem and
applying a fix, I deleted the *.ll.out files, re-compiled and re-analysed the
codebase to verify that the fix has removed the problem.

[1]: https://github.com/xiw/stack

Joe Stringer (4):
  ofp-parse: Fix typo in consistency check.
  vtep-ctl: Remove extraneous NULL pointer check.
  ovs-vsctl: Remove redundant checks.
  ovn: Fix extra token detection.

 lib/ofp-parse.c       | 2 +-
 ovn/lib/expr.c        | 2 +-
 tests/ovs-ofctl.at    | 8 ++++----
 utilities/ovs-vsctl.c | 9 +++------
 vtep/vtep-ctl.c       | 9 ++-------
 5 files changed, 11 insertions(+), 19 deletions(-)

--
2.1.4
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to