https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112639
Bug ID: 112639 Summary: Incorrect handling of __builtin_c[lt]zg argument side-effects Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target Milestone: --- unsigned long long b = 0; int foo (void) { return __builtin_clzg (b++, __SIZEOF_LONG__ * __CHAR_BIT__); } int bar (void) { return __builtin_ctzg (b++, __SIZEOF_LONG__ * __CHAR_BIT__); } int main () { if (foo () != __SIZEOF_LONG__ * __CHAR_BIT__ || b != 1) __builtin_abort (); if (foo () != __SIZEOF_LONG__ * __CHAR_BIT__ - 1 || b != 2) __builtin_abort (); if (foo () != __SIZEOF_LONG__ * __CHAR_BIT__ - 2 || b != 3) __builtin_abort (); b = 0; if (bar () != __SIZEOF_LONG__ * __CHAR_BIT__ || b != 1) __builtin_abort (); if (bar () != 0 || b != 2) __builtin_abort (); if (bar () != 1 || b != 3) __builtin_abort (); } is miscompiled.