https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103046
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:155f6b2be421b0f84e478e34fbf72ee0bb9e36bc commit r12-4933-g155f6b2be421b0f84e478e34fbf72ee0bb9e36bc Author: Jakub Jelinek <ja...@redhat.com> Date: Fri Nov 5 10:20:10 2021 +0100 dwarf2out: Fix up CONST_WIDE_INT handling once more [PR103046] My last change to CONST_WIDE_INT handling in add_const_value_attribute broke handling of CONST_WIDE_INT constants like ((__uint128_t) 1 << 120). wi::min_precision (w1, UNSIGNED) in that case 121, but wide_int::from creates a wide_int that has 0 and 0xff00000000000000ULL in its elts and precision 121. When we output that, we output both elements and thus emit 0, 0xff00000000000000 instead of the desired 0, 0x0100000000000000. IMHO we should actually pass machine_mode to add_const_value_attribute from callers, so that we know exactly what precision we want. Because hypothetically, if say mode is OImode and the CONST_WIDE_INT value fits into 128 bits or 192 bits, we'd emit just those 128 or 192 bits but debug info users would expect 256 bits. On typedef unsigned __int128 U; int main () { U a = (U) 1 << 120; U b = 0xffffffffffffffffULL; U c = ((U) 0xffffffff00000000ULL) << 64; return 0; } vanilla gcc incorrectly emits 0, 0xff00000000000000 for a, 0xffffffffffffffff alone (DW_FORM_data8) for b and 0, 0xffffffff00000000 for c. gcc with the previously posted PR103046 patch emits 0, 0x0100000000000000 for a, 0xffffffffffffffff alone for b and 0, 0xffffffff00000000 for c. And with this patch we emit 0, 0x0100000000000000 for a, 0xffffffffffffffff, 0 for b and 0, 0xffffffff00000000 for c. So, the patch below certainly causes larger debug info (well, 128-bit integers are pretty rare), but in this case the question is if it isn't more correct, as debug info consumers generally will not know if they should sign or zero extend the value in DW_AT_const_value. The previous code assumes they will always zero extend it... 2021-11-05 Jakub Jelinek <ja...@redhat.com> PR debug/103046 * dwarf2out.c (add_const_value_attribute): Add MODE argument, use it in CONST_WIDE_INT handling. Adjust recursive calls. (add_location_or_const_value_attribute): Pass DECL_MODE (decl) to new add_const_value_attribute argument. (tree_add_const_value_attribute): Pass TYPE_MODE (type) to new add_const_value_attribute argument.