public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/103046] New: Incorrect debug info for uint128 bit shift in gcc 11.2
@ 2021-11-02 14:11 liyd2021 at gmail dot com
  2021-11-02 15:46 ` [Bug debug/103046] [11/12 Regression] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: liyd2021 at gmail dot com @ 2021-11-02 14:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103046

            Bug ID: 103046
           Summary: Incorrect debug info for uint128 bit shift in gcc 11.2
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liyd2021 at gmail dot com
  Target Milestone: ---

Affected versions: gcc 11.2.0 with gdb (Ubuntu 20.04.2)

gcc11.2 generates wrong debug when left shift uint128 value for more than 64
bits.
The debug info shows variable `a` has a const value `0xff00...` while the
actual value of `a` is `0x0100...`
This bug cannot be reproduced in gcc 10 or 9.

(terminal) $ cat a.c && gcc -g -Og a.c
typedef unsigned __int128 U;

__attribute__((noipa)) void foo(U x) {}

int main() {
    U a = (U) 1 << 120;
    foo(a);
}
--------------------
(terminal) $ cat run.gdb
b 7
b foo
r
p/x a
c
p/x x
--------------------
(terminal) $ gdb -x run.gdb a.out
Breakpoint 1 at 0x40116e: file a.c, line 7.
Breakpoint 2 at 0x401169: file a.c, line 3.

Breakpoint 1, main () at a.c:7
7           foo(a);
$1 = 0xff000000000000000000000000000000 <- **BUG**: wrong value

Breakpoint 2, foo (x=1329227995784915872903807060280344576) at a.c:3
3       __attribute__((noipa)) void foo(U x) {}
$2 = 0x1000000000000000000000000000000 <- correct value

--------------------
debug info and assembly:

<2><61>: Abbrev Number: 5 (DW_TAG_variable)
    <62>   DW_AT_name        : a
    <64>   DW_AT_decl_file   : 1
    <65>   DW_AT_decl_line   : 6
    <66>   DW_AT_decl_column : 7
    <67>   DW_AT_type        : <0x2e>
    <6b>   DW_AT_const_value : 0xff000000000000000000000000000000

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/103046] [11/12 Regression] Incorrect debug info for uint128 bit shift in gcc 11.2
  2021-11-02 14:11 [Bug debug/103046] New: Incorrect debug info for uint128 bit shift in gcc 11.2 liyd2021 at gmail dot com
@ 2021-11-02 15:46 ` jakub at gcc dot gnu.org
  2021-11-05  9:23 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-11-02 15:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103046

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.3
     Ever confirmed|0                           |1
            Summary|Incorrect debug info for    |[11/12 Regression]
                   |uint128 bit shift in gcc    |Incorrect debug info for
                   |11.2                        |uint128 bit shift in gcc
                   |                            |11.2
                 CC|                            |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2021-11-02
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with my r11-7757-gfc9c4e5fc50c7fcbd27d6cb3dd372f7da8216954 aka PR99562
change.
Untested fix:
2021-11-02  Jakub Jelinek  <jakub@redhat.com>

        PR debug/103046
        * dwarf2out.c (add_const_value_attribute) <case CONST_WIDE_INT>: Round
        prec up to next HOST_BITS_PER_WIDE_INT multiple.

--- gcc/dwarf2out.c.jj  2021-10-08 10:52:47.086531820 +0200
+++ gcc/dwarf2out.c     2021-11-02 16:25:24.505504356 +0100
@@ -20102,6 +20102,7 @@ add_const_value_attribute (dw_die_ref di
        unsigned int prec = MIN (wi::min_precision (w1, UNSIGNED),
                                 (unsigned int) CONST_WIDE_INT_NUNITS (rtl)
                                 * HOST_BITS_PER_WIDE_INT);
+       prec = ROUND_UP (prec, HOST_BITS_PER_WIDE_INT);
        wide_int w = wide_int::from (w1, prec, UNSIGNED);
        add_AT_wide (die, DW_AT_const_value, w);
       }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/103046] [11/12 Regression] Incorrect debug info for uint128 bit shift in gcc 11.2
  2021-11-02 14:11 [Bug debug/103046] New: Incorrect debug info for uint128 bit shift in gcc 11.2 liyd2021 at gmail dot com
  2021-11-02 15:46 ` [Bug debug/103046] [11/12 Regression] " jakub at gcc dot gnu.org
@ 2021-11-05  9:23 ` cvs-commit at gcc dot gnu.org
  2021-11-05 13:38 ` [Bug debug/103046] [11 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-05  9:23 UTC (permalink / raw)
  To: gcc-bugs

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 <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:155f6b2be421b0f84e478e34fbf72ee0bb9e36bc

commit r12-4933-g155f6b2be421b0f84e478e34fbf72ee0bb9e36bc
Author: Jakub Jelinek <jakub@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  <jakub@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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/103046] [11 Regression] Incorrect debug info for uint128 bit shift in gcc 11.2
  2021-11-02 14:11 [Bug debug/103046] New: Incorrect debug info for uint128 bit shift in gcc 11.2 liyd2021 at gmail dot com
  2021-11-02 15:46 ` [Bug debug/103046] [11/12 Regression] " jakub at gcc dot gnu.org
  2021-11-05  9:23 ` cvs-commit at gcc dot gnu.org
@ 2021-11-05 13:38 ` rguenth at gcc dot gnu.org
  2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
  2021-11-29  9:08 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-05 13:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103046

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
      Known to work|                            |12.0
            Summary|[11/12 Regression]          |[11 Regression] Incorrect
                   |Incorrect debug info for    |debug info for uint128 bit
                   |uint128 bit shift in gcc    |shift in gcc 11.2
                   |11.2                        |

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
fixed on trunk.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/103046] [11 Regression] Incorrect debug info for uint128 bit shift in gcc 11.2
  2021-11-02 14:11 [Bug debug/103046] New: Incorrect debug info for uint128 bit shift in gcc 11.2 liyd2021 at gmail dot com
                   ` (2 preceding siblings ...)
  2021-11-05 13:38 ` [Bug debug/103046] [11 " rguenth at gcc dot gnu.org
@ 2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
  2021-11-29  9:08 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-29  8:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103046

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:41db2576afc4f3bf993778ad80529f2bf4ddd6cf

commit r11-9328-g41db2576afc4f3bf993778ad80529f2bf4ddd6cf
Author: Jakub Jelinek <jakub@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  <jakub@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.

    (cherry picked from commit 155f6b2be421b0f84e478e34fbf72ee0bb9e36bc)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug debug/103046] [11 Regression] Incorrect debug info for uint128 bit shift in gcc 11.2
  2021-11-02 14:11 [Bug debug/103046] New: Incorrect debug info for uint128 bit shift in gcc 11.2 liyd2021 at gmail dot com
                   ` (3 preceding siblings ...)
  2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
@ 2021-11-29  9:08 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-11-29  9:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103046

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 11.3 too.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-29  9:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-02 14:11 [Bug debug/103046] New: Incorrect debug info for uint128 bit shift in gcc 11.2 liyd2021 at gmail dot com
2021-11-02 15:46 ` [Bug debug/103046] [11/12 Regression] " jakub at gcc dot gnu.org
2021-11-05  9:23 ` cvs-commit at gcc dot gnu.org
2021-11-05 13:38 ` [Bug debug/103046] [11 " rguenth at gcc dot gnu.org
2021-11-29  8:49 ` cvs-commit at gcc dot gnu.org
2021-11-29  9:08 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).