https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128554
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:f826f8df629589f6673cf65d941db648cff34f54 commit r17-6718-gf826f8df629589f6673cf65d941db648cff34f54 Author: Jakub Jelinek <[email protected]> Date: Thu Nov 26 09:27:06 2026 +0100 c: Avoid bogus -Wshift-count-negative warning on __builtin_stdc_bit_{floor,ceil} [PR128554] As documented earlier in c_parser_postfix_expression, we lower __builtin_stdc_bit_{floor,ceil} calls as __builtin_stdc_bit_floor (arg) as arg == 0 ? (type) 0 : (type) 1 << (prec - 1 - __builtin_clzg (arg)) __builtin_stdc_bit_ceil (arg) as arg <= 1 ? (type) 1 : (type) 2 << (prec - 1 - __builtin_clzg (arg - 1)) Now, we have /* For __builtin_stdc_bit_ceil (0U) or __builtin_stdc_bit_ceil (1U) or __builtin_stdc_bit_floor (0U) avoid bogus -Wshift-count-* warnings. The LSHIFT_EXPR is in dead code in that case. */ if (integer_zerop (arg) || (stdc_rid == C_BUILTIN_STDC_BIT_CEIL && integer_onep (arg))) expr.value = build_int_cst (type, 0); else so that we don't emit bogus warning on dead code emitted that way for __builtin_stdc_bit_{floor,ceil} (0) or __builtin_stdc_bit_ceil (1). As this testcase shows, we can still get a bogus warning on the dead code if during c_fully_fold the argument is propagated anyway. The following patch fixes it by suppressing the warning on the LSHIFT_EXPR and checking such suppression before doing the warning as well. 2026-11-25 Jakub Jelinek <[email protected]> PR c/128554 * c-parser.cc (c_parser_postfix_expression): Suppress OPT_Wshift_count_negative warnings on LSHIFT_EXPR. * c-fold.cc (c_fully_fold_internal): Don't emit OPT_Wshift_count_negative warning if suppressed. * gcc.dg/pr128554.c: New test. Reviewed-by: Joseph Myers <[email protected]>
