<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">UBSan has an object size check (-fsanitize=object-size) which can determine when an object is not large enough to represent a value of its type. The check uses the @llvm.objectsize intrinsic to determine the size of objects.<br class=""><br class="">AFAICT, and please let me know if I've missed something here, @llvm.objectsize always conservatively returns "I don't know" (i.e -1) at -O0, which means that it can't catch any issues at -O0. This is a problem because there is a substantial compile-time cost to enabling the object size check in debug builds. It seems unlikely that we can make @llvm.objectsize more precise at -O0 without regressing compile time and the debugging experience in other ways.<br class=""><br class="">So, I'm proposing that we disable ubsan's object size check at -O0. This will speed up debug builds without compromising on diagnostic quality. E.g I measured a 26% decrease in the compile time for X86FastISel.cpp with this change, and a 32% decrease in the *.o size:<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">No ubsan [1]</div><div class="">-----------------</div><div class="">Average compile time: 5.27 s</div><div class="">X86FastISel.cpp.o size: 3.06 MB</div><div class=""><br class=""></div><div class="">Ubsan [2]</div><div class=""><div class="">-------------</div></div><div class=""><div class="">Average compile time: 9.49 s</div></div><div class=""><div class="">X86FastISel.cpp.o size: 8.93 MB</div></div><div class=""><div class=""><br class=""></div></div><div class=""><div class="">Ubsan without the object size check [3]</div></div><div class=""><div class="">----------------------------------------------------</div></div><div class=""><div class="">Average compile time: 6.99 s</div></div><div class=""><div class="">X86FastISel.cpp.o size: 6.06 MB</div></div></blockquote><div class=""><br class=""></div><div class="">There's reason to expect similar compile-time / binary size savings with other *.cpp files. The object size check is in the same category of checks as the null check and the alignment check. This group of checks accounts for the vast majority of checks inserted by ubsan (over 90% in some macOS apps), so any savings here would be helpful.<br class=""><br class="">Any objections? Anyone else in favor?<br class=""><br class="">thanks,<br class="">vedant<br class=""><div class=""><br class=""></div><div class="">[1] -O0 -g<br class="">[2] -O0 -g -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=vptr,function</div><div class="">[3] -O0 -g -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=vptr,function,object-size</div></div></body></html>