-fsantize=undefined

512 views
Skip to first unread message

Ben Goodrich

unread,
May 5, 2013, 2:36:57 AM5/5/13
to stan...@googlegroups.com
Adding -fsanitize=undefined to CFLAGS to check for undefined behavior as described in this blog post

http://blog.llvm.org/2013/04/testing-libc-with-fsanitizeundefined.html#more

turned up these errors in stack_alloc_test.cpp

src/test/memory/stack_alloc_test.cpp:28:5: runtime error: store to misaligned address 0x00000101b135 for type 'double', which requires 8 byte alignment
src
/test/memory/stack_alloc_test.cpp:31:5: runtime error: store to misaligned address 0x00000101b13d for type 'int', which requires 4 byte alignment
src
/test/memory/stack_alloc_test.cpp:38:5: runtime error: load of misaligned address 0x00000101b135 for type 'double', which requires 8 byte alignment
src
/test/memory/stack_alloc_test.cpp:39:5: runtime error: reference binding to misaligned address 0x00000101b13d for type 'const int', which requires 4 byte alignment
src
/test/memory/stack_alloc_test.cpp:43:5: runtime error: load of misaligned address 0x00000101b135 for type 'double', which requires 8 byte alignment
src
/test/memory/stack_alloc_test.cpp:44:5: runtime error: reference binding to misaligned address 0x00000101b13d for type 'const int', which requires 4 byte alignment

which I don't understand at all. Also, there are some errors from the libraries, most of which looked as if they weren't our fault, but the following ones might be

lib/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:153:16: runtime error: reference binding to null pointer of type 'const double'
lib
/eigen_3.1.3/Eigen/src/Core/Transpose.h:134:14: runtime error: reference binding to null pointer of type 'const Scalar' (aka 'const double')
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:140:16: runtime error: reference binding to null pointer of type 'double'
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:153:16: runtime error: reference binding to null pointer of type 'const stan::agrad::var'
lib
/eigen_3.1.3/Eigen/src/Core/Transpose.h:134:14: runtime error: reference binding to null pointer of type 'const Scalar' (aka 'const stan::agrad::var')
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:140:16: runtime error: reference binding to null pointer of type 'stan::agrad::var'
lib
/gtest_1.6.0/include/gtest/gtest.h:1353:24: runtime error: reference binding to misaligned address 0x00000101b13d for type 'const int', which requires 4 byte alignment
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:153:16: runtime error: reference binding to null pointer of type 'const double'
lib
/eigen_3.1.3/Eigen/src/Core/Transpose.h:134:14: runtime error: reference binding to null pointer of type 'const Scalar' (aka 'const double')
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:140:16: runtime error: reference binding to null pointer of type 'double'
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:153:16: runtime error: reference binding to null pointer of type 'const double'
lib
/eigen_3.1.3/Eigen/src/Core/Functors.h:495:76: runtime error: division by zero
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:153:16: runtime error: reference binding to null pointer of type 'const double'
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:140:16: runtime error: reference binding to null pointer of type 'double'
lib
/eigen_3.1.3/Eigen/src/Core/Functors.h:495:76: runtime error: division by zero
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:153:16: runtime error: reference binding to null pointer of type 'const stan::agrad::var'
lib
/eigen_3.1.3/Eigen/src/Core/Transpose.h:134:14: runtime error: reference binding to null pointer of type 'const Scalar' (aka 'const stan::agrad::var')
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:140:16: runtime error: reference binding to null pointer of type 'stan::agrad::var'
lib
/eigen_3.1.3/Eigen/src/Core/Functors.h:495:76: runtime error: division by zero
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:153:16: runtime error: reference binding to null pointer of type 'const stan::agrad::var'
lib
/eigen_3.1.3/Eigen/src/Core/Transpose.h:134:14: runtime error: reference binding to null pointer of type 'const Scalar' (aka 'const stan::agrad::var')
lib
/eigen_3.1.3/Eigen/src/Core/PlainObjectBase.h:140:16: runtime error: reference binding to null pointer of type 'stan::agrad::var'

The full log is attached, which has whatever context there is for each of these things that you can grep for.

Ben

output.txt

Bob Carpenter

unread,
May 5, 2013, 1:39:02 PM5/5/13
to stan...@googlegroups.com
Interesting. I originally tried to tweak stack_alloc so
that it always generated aligned results. We want this to
be aligned because even when the compiler/runtime can handle
non-alignment, it's much faster to have memory aligned.

Could someone else take a look at this who perhaps knows
more than me about memory alignment? The code that attempts
to align is all in memory/stack_alloc.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Ben Goodrich

unread,
May 5, 2013, 1:46:43 PM5/5/13
to stan...@googlegroups.com
FWIW, there are also allignment messages in Eigen itself. Attached is a better logfile that captures both stderr and stdout so that you can see the context of the "runtime error:" better.

Ben
output2.txt
Reply all
Reply to author
Forward
0 new messages