Hey. Am 11.03.2019 um 12:17 schrieb Jakub Jelinek:
On Mon, Mar 11, 2019 at 11:06:37AM +0000, Moritz Strübe wrote: On 11.03.2019 at 10:14 Jakub Jelinek wrote: You could build with -fsanitize=undefined, that would tell you at runtime you have undefined behavior in your code (if the SingleDiff has bit ever 0x20 set). Yes, that helps. Unfortunately I'm on an embedded system, thus the code size increase is just too big. You can -fsanitize-undefined-trap-on-error, which doesn't increase size too much, it is less user-friendly, but still should catch the UB. Ok, I played around a bit. Interestingly, if I set -fsanitize=udefined and -fsanitize-undefined-trap-on-error the compiler detects that it will always trap, and optimizes the code accordingly (the code after the trap is removed).* Which kind of brings me to David's argument: Shouldn't the compiler warn if there is undefined behavior it certainly knows of? I do assume though that fsanitize just injects the test-code everywhere and relies on the compiler to remove it at unnecessary places. Would be nice, though. :) Cheers Morty *After fixing the code, it got too big to fit. -- Redheads Ltd. Softwaredienstleistungen Schillerstr. 14 90409 Nürnberg Telefon: +49 (0)911 180778-50 E-Mail: moritz.stru...@redheads.de<mailto:moritz.stru...@redheads.de> | Web: www.redheads.de<http://www.redheads.de> Geschäftsführer: Andreas Hanke Sitz der Gesellschaft: Lauf Amtsgericht Nürnberg HRB 22681 Ust-ID: DE 249436843