[vtk-developers] clang undefined behaviour sanitizer overview

Sean McBride sean at rogue-research.com
Thu Feb 28 14:38:18 EST 2013


Hi all,

So at the VTK hack-a-thon yesterday I showed some of you clang's 'undefined behaviour sanitizer' (abbreviated 'ubsan').  If you want to try it yourself, you need to build clang from svn, which is easy and can be done with CMake:

<http://clang.llvm.org/get_started.html>

I recommend setting CMAKE_BUILD_TYPE=Release and LLVM_ENABLE_ASSERTIONS=ON.

Then you just use your new clang executable with "-fsanitize=undefined" as a C/C++ flag.  Should work on linux or OS X.  It's described here:

<http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation>

It may report many things, and can be too noisy, so you can specify a subset of checks.  For VTK, I've been using "-fsanitize=bool,bounds,float-cast-overflow,integer-divide-by-zero,null,object-size,return,shift,signed-integer-overflow,unreachable,vla-bound" and this triggers only a few issues, some of which we fixed at the hack-a-thon:

<http://review.source.kitware.com/10021>
<http://review.source.kitware.com/10026>

Notice that its output nicely pinpoints the problem:

vtkOOGLExporter.cxx:228:3: runtime error: index -4 out of bounds for type 'char [256]'
vtkOrderedTriangulator.cxx:1609  runtime error: index 8 out of bounds for type 'TemplateIDType [8]'

And we found one false-positive (so you should maybe not use 'float-cast-overflow' for now):

<http://llvm.org/PR15383>

I'll be turning these on on my Rogue7 dashboard bit by bit...

(clang also has AddressSanitizer, ThreadSanitizer, and MemorySanitizer, which look very interesting too, but I have not yet tried them.)

Cheers,

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada





More information about the vtk-developers mailing list