https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70967
Bug ID: 70967 Summary: doc: Please document rotate idiom Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: hpa at zytor dot com Target Milestone: --- The idiom that gcc has recognized since time immemorial (gcc 2-something) to generate a rotate: ((foo >> n) + (foo << (sizeof(foo) * CHAR_BIT - n)) /* | instead of + has been recognized for almost but not quite as long */ ... is undefined behavior under the C standard when n == 0. There is a technically portable idiom (bug 57157) which has been recognized since gcc 4.6.3, but that is not portable to older versions of gcc without generating suboptimal code. It would be great if the gcc manual could be augmented to document this idiom for rotate as a GNU C extension so that people are less concerned about its validity, and compilers that mimic the GNU C dialect (icc, clang, etc.) know to implement it correctly.