GCC turns &~ into | due to undefined bit-shift without warning
Christophe Lyon
christophe.lyon@st.com
Wed Mar 20 14:26:00 GMT 2019
On 20/03/2019 15:08, Moritz Strübe wrote:
> 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.
>
>
Wouldn't this fail to link? I thought the sanitizers need some runtime libraries which are only available under linux/macos/android. What do you mean by embedded? Isn't it arm-eabi?
>
> 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. :)
>
Could you confirm in which version of the ST libraries you noticed this bug?
I'm told it was fixed on 23-march-2018.
Thanks,
Christophe
> 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.struebe@redheads.de<mailto:moritz.struebe@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
>
More information about the Gcc
mailing list