3 ms·
I don't remember what UBSan looked like in 2014, but it does something not entirely unhelpful for each of these examples, although they are caught at run time,
by SloopJon 6y ago
I don't remember what UBSan looked like in 2014, but it does something not entirely unhelpful for each of these examples, although they are caught at run time, not compile time:
runtime error: index 4 out of bounds for type 'int [4]'
UndefinedBehaviorSanitizer: SEGV on unknown addres
runtime error: reference binding to null pointer of type 'int'
- logicchop 6y ago> although they are caught at run time, not compile time Not if the compiler got to it first. If the compiler does what Chen points out it can do, you won't be indexing anything at run time.
- saagarjha 6y agoAt -O0, the compiler will generally not do any of that analysis.
- klodolph 6y agoGCC doesn’t enable -fdelete-null-pointer-checks until -O2, so even -O1 might work fairly well.
- klodolph 6y agoIs that true? The compiler is being explicitly instructed to (try to) detect undefined behavior where it happens. This is the difference between tools like UBSan and tools like Valgrind. Valgrind is low-level, it’s a virtual x86, so the optimizer runs first. UBSan is high-level, it instruments the code using the compiler, and presumably the compiler can be directed to preserve the instrumentation.
- SloopJon 6y agoI see the same errors using Clang with -O1, -O2, and -O3.
- CodesInChaos 6y agoUBsan is part of the compiler, so it inserts runtime checks before the optimization passes which rely on undefined behaviour run.