https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127383
--- Comment #9 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:d7fa48a8500bcfaa1cf4ae3f917c22aa6ec7c75f commit r17-4374-gd7fa48a8500bcfaa1cf4ae3f917c22aa6ec7c75f Author: Jakub Jelinek <[email protected]> Date: Wed Sep 16 22:22:20 2026 +0200 c: Fix up integer promotion of bit-precise bit-fields [PR127383] The following testcases are miscompiled when a bit-precise integer bit-field is explicitly cast to a non-cv-qualified bit-precise integer (of the same signedness) with precision of the bit-field width. We can then incorrectly apply an integer promotion of the bit-field to the corresponding bit-precise integer, even when it shouldn't be applied (because it is a cast rather than the bit-field itself). Regardless of the cv-qualifications, the TREE_TYPE of the FIELD_DECLs (and COMPONENT_REFs) is a cv-unqualified BITINT_TYPE. We first call convert to that type in convert_lvalue_to_rvalue and that doesn't change anything. If there is an explicit cast to the same type as the TREE_TYPE of the COMPONENT_REF has, we usually wrap it into a NON_LVALUE_EXPR, because the COMPONENT_REF is usually an lvalue (but as can be seen in the testcases, not always). So the second hunk makes sure to add NON_LVALUE_EXPR around the COMPONENT_REF even in the (cast) foo ().a cases to distinguish it from foo ().a. The second change is in default_conversion, for the promotion of bit-fields of bit-precise integer type we don't promote them if they are wrapped in some cast or NON_LVALUE_EXPR (the function normally uses STRIP_TYPE_NOPS). 2026-09-16 Jakub Jelinek <[email protected]> PR c/127383 * c-typeck.cc (default_conversion): If orig_expr is different from exp and exp is a bit-field of bit-precise integer type, call perform_integral_promotions on orig_exp rather than exp. (build_c_cast): Wrap in NON_LVALUE_EXPR not just lvalues, but also non-lvalue bit-fields of bit-precise integer type. * gcc.dg/torture/bitint-108.c: New test. * gcc.dg/bitint-143.c: New test. * gcc.dg/bitint-144.c: New test. Reviewed-by: Joseph Myers <[email protected]>
