On 29 Dec 2023 00:52, Joseph Myers wrote: > On Sun, 24 Dec 2023, Mike Frysinger wrote: > > The sim expects left shift operations on negative values to have two's > > compliment behavior, and right shift operations to sign extend. In C89, > > this was not explicitly mentioned. In C90, this was changed to undefined > > behavior. In C23, this was settled as the behavior we want in N2412 [1]. > > No, there has been no change in C23 to the rules for which shifts are > undefined. The change made was to make *representations* of integer types > defined as two's complement; there were no changes to semantics of > *operations* on such types. thanks, i thought the meat of P0907 was adopted, albeit via a diff proposal. not that the final thing adopted was only about twos compliment representation. looking closer at the source of the warnings, it seems to all come from the macro that creates a 64-bit value from 2 32-bit values, and specifically when shifting a negative constant into the upper 32-bits. but we don't need to make the upper 32-bits signed before shifting since we're going to throw away all of the initial upper 32-bits, so we can prob fix this with: -#define MAKEDI(hi, lo) ((((int64_t) (int32_t) (hi)) << 32) | ((uint64_t) (uint32_t) (lo))) +#define MAKEDI(hi, lo) ((((int64_t) (uint32_t) (hi)) << 32) | ((uint64_t) (uint32_t) (lo))) for clarity, i'm kind of inclined to do the operations only as unsigned, rely on the types to do the appropriate truncation/extension, and then convert to signed at the end. #define MAKEDI(hi, lo) ( \ (int64_t)( \ ((uint64_t)(hi) << 32)) | (uint32_t) (lo) \ ) \ ) there's prob more left shifting of negative values lurking in the tree, but none that trigger compile-time warnings, so i'm inclined to not audit. the harder part would be implementing sign extension with right shifts, so hopefully we never have to cross that bridge. -mike