On Tue, Nov 17, 2020 at 06:23:51PM +0100, Philipp Tomsich wrote: > The rules for E1 << E2 are: > - if E2 is negative => undefined > - if E1 is unsigned => E1 x 2^E2, reduced module one more than the > maximum representable value > - if E1 is signed and non-negative => E1 x 2^E2, if E1 x 2^E2 is > representable; otherwise, undefined
Those are rules about UB -fsanitize=shift-base diagnoses, and that greatly differs between different languages and versions of those languages, and as we don't really record what it comes from, for the GIMPLE IL everything is well defined. What we were talking about before is written earlier in the "If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined." sentence and is what -fsanitize=shift-exponent diagnoses. In the GIMPLE IL such shifts are still UB and in RTL only depending on some target macros (i.e. undefined for some targets, wrapping with some mask or saturating on others). Jakub