3

On travis CI where I use clang version 3.4 (tags/RELEASE_34/final) which is already installed, I build my code with this:

clang++ main.cpp -m64 -fsanitize=undefined -Werror -std=c++98 -pedantic -pedantic-errors -fvisibility=hidden -fstrict-aliasing -Weverything -Qunused-arguments -fcolor-diagnostics -O3 -DNDEBUG

(this command is obtained from compile_commands.json which is generated from cmake)

And in the output after the program quits some numbers (like hex representation of memory) appear:

00 00 00  10 70 fb 01 00 00 00 00  10 70 fb 01

My guess is this is from the UB sanitizer because when I build with ASAN or no sanitizer at all these numbers aren't there.

So what do they mean? How do I diagnose my UB error (if this is indeed such)?

I thought when a sanitizer encounters an error it crashes the program and prints a big message with explanation. So what is this?

This is a deal breaker for me because I compare reference output in a text file with the output of the program from the current build and such additional output breaks everything.

I tried locally using Clang 3.6, which is the default for my Ubuntu using the same build command, but when I run the executable I get no errors or such additional output.

here is the failing build on travis - and I don't think my code is relevant because my problem is with the sanitizer output not being helpful at all.

onqtam
  • 4,356
  • 2
  • 28
  • 50

1 Answers1

1

I also enabled the builds with clang 3.5/3.6/3.7/3.8 and turns out clang 3.5 behaves the same way...

clang 3.6 however gives more output!

  20 6c 98 01 00 00 00 00  20 6c 98 01 00 00 00 00  20 6c 98 01
              ^ 
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/bits/stl_tree.h:247:17: runtime error: upcast of address 0x00000115e090 with insufficient space for an object of type 'std::_Rb_tree_node<doctest::detail::TestData>'
0x00000115e090: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  20 6c 98 01 00 00 00 00  20 6c 98 01 00 00 00 00  20 6c 98 01

clang 3.7 and 3.8 give the same output as 3.6

I am using libstdc++ so I will switch to libc++ to hopefully remove this error (which I think is not from my code!)

I was using a simple TestData structure inside a std::set<>...

onqtam
  • 4,356
  • 2
  • 28
  • 50