public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1
@ 2023-12-06 10:51 iamanonymous.cs at gmail dot com
  2024-01-19 15:57 ` [Bug c/112878] " zsojka at seznam dot cz
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2023-12-06 10:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112878
           Summary: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23
                    -gctf1
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---

*******************************************************************************
OS and Platform:
$ uname -a:
Linux ubuntu 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023
x86_64 x86_64 x86_64 GNU/Linux
*******************************************************************************
gcc version:
$ gcc -v
Using built-in specs.
COLLECT_GCC=/root/gcc_set/202311291030/bin/gcc
COLLECT_LTO_WRAPPER=/root/gcc_set/202311291030/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/root/gcc_set/202311291030
--with-gmp=/root/build_essential --with-mpfr=/root/build_essential
--with-mpc=/root/build_essential --enable-languages=c,c++ --disable-multilib
--with-sanitizer=address,undefined,thread,leak
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20231129 (experimental) (GCC) 

git version: 99fa0bfd63d97825c4221dcd3123940f1d0e6291
*******************************************************************************
Program:
$ cat mutant.c
struct {
  _BitInt(282) a : 280;
} b;

*******************************************************************************
Command Lines:
$ gcc -std=c23 -gctf1 mutant.c
mutant.c:3:1: internal compiler error: in ctf_add_slice, at ctfc.cc:499
    3 | } b;
      | ^
0x8d0e95 ctf_add_slice(ctf_container*, unsigned int, unsigned long, unsigned
int, unsigned int, die_struct*)
        ../../gcc/gcc/ctfc.cc:499
0xb6a770 gen_ctf_sou_type
        ../../gcc/gcc/dwarf2ctf.cc:617
0xb69fb7 gen_ctf_type
        ../../gcc/gcc/dwarf2ctf.cc:892
0xb6aa61 ctf_do_die(die_struct*)
        ../../gcc/gcc/dwarf2ctf.cc:978
0xbbc62b ctf_debug_do_cu
        ../../gcc/gcc/dwarf2out.cc:32985
0xbbc62b ctf_debug_do_cu
        ../../gcc/gcc/dwarf2out.cc:32978
0xbbc62b dwarf2out_early_finish
        ../../gcc/gcc/dwarf2out.cc:33114
0xb2411f symbol_table::finalize_compilation_unit()
        ../../gcc/gcc/cgraphunit.cc:2578
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Also ICE on trunk, compiler explorer: https://godbolt.org/z/8ozb8MrPr

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

* [Bug c/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1
  2023-12-06 10:51 [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1 iamanonymous.cs at gmail dot com
@ 2024-01-19 15:57 ` zsojka at seznam dot cz
  2024-01-20  9:02 ` [Bug debug/112878] " pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: zsojka at seznam dot cz @ 2024-01-19 15:57 UTC (permalink / raw)
  To: gcc-bugs

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

Zdenek Sojka <zsojka at seznam dot cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |zsojka at seznam dot cz

--- Comment #1 from Zdenek Sojka <zsojka at seznam dot cz> ---
Also fails with a union:
$ cat testcase.c 
union {
  _BitInt(448) f2 : 1;
} b;
$ x86_64-pc-linux-gnu-gcc -gbtf testcase.c 
testcase.c:3:1: internal compiler error: in ctf_add_slice, at ctfc.cc:499
    3 | } b;
      | ^
0xd60e19 ctf_add_slice(ctf_container*, unsigned int, unsigned long, unsigned
int, unsigned int, die_struct*)
        /repo/gcc-trunk/gcc/ctfc.cc:499
0x101d9d0 gen_ctf_sou_type
        /repo/gcc-trunk/gcc/dwarf2ctf.cc:617
0x101d177 gen_ctf_type
        /repo/gcc-trunk/gcc/dwarf2ctf.cc:892
...

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

* [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1
  2023-12-06 10:51 [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1 iamanonymous.cs at gmail dot com
  2024-01-19 15:57 ` [Bug c/112878] " zsojka at seznam dot cz
@ 2024-01-20  9:02 ` pinskia at gcc dot gnu.org
  2024-04-09 18:34 ` [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with _BitInt > 255 in a struct and -gctf1 ibhagat at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-20  9:02 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-01-20

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

The assert is obvious hitting because the bit_size is greater than 255:


  gcc_assert ((bit_size <= 255) && (bit_offset <= 255));

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

* [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with _BitInt > 255 in a struct and -gctf1
  2023-12-06 10:51 [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1 iamanonymous.cs at gmail dot com
  2024-01-19 15:57 ` [Bug c/112878] " zsojka at seznam dot cz
  2024-01-20  9:02 ` [Bug debug/112878] " pinskia at gcc dot gnu.org
@ 2024-04-09 18:34 ` ibhagat at gcc dot gnu.org
  2024-04-09 18:44 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ibhagat at gcc dot gnu.org @ 2024-04-09 18:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Indu Bhagat <ibhagat at gcc dot gnu.org> ---
The limit of 255 is somewhat arbitrary but we need to follow it for now,
because libctf has a check in ctf_add_slice () in libctf/ctf-create.c :

  if ((ep->cte_bits > 255) || (ep->cte_offset > 255))
    return (ctf_set_typed_errno (fp, ECTF_SLICEOVERFLOW));
  ...
  slice.cts_bits = ep->cte_bits;
  slice.cts_offset = ep->cte_offset; 

The CTF generation in GCC does not have a mechanism to roll-back an already
added type.  In this testcase presented in the PR, we hit a representation
limit in CTF slices (for a member of a struct) and ICE, after the type for
struct (CTF_K_STRUCT) has already been added to the container.

To exit gracefully instead in GCC, one option is to simply check for both the
offset and size of the bitfield to be explicitly <= 255.  If the check fails,
we emit the member with type CTF_K_UNKNOWN instead.

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

* [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with _BitInt > 255 in a struct and -gctf1
  2023-12-06 10:51 [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1 iamanonymous.cs at gmail dot com
                   ` (2 preceding siblings ...)
  2024-04-09 18:34 ` [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with _BitInt > 255 in a struct and -gctf1 ibhagat at gcc dot gnu.org
@ 2024-04-09 18:44 ` pinskia at gcc dot gnu.org
  2024-04-09 21:18 ` ibhagat at gcc dot gnu.org
  2024-04-11  0:32 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-09 18:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Another option to ouput a sorry message and then suspend this until libctf gets
fixed/changed.

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

* [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with _BitInt > 255 in a struct and -gctf1
  2023-12-06 10:51 [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1 iamanonymous.cs at gmail dot com
                   ` (3 preceding siblings ...)
  2024-04-09 18:44 ` pinskia at gcc dot gnu.org
@ 2024-04-09 21:18 ` ibhagat at gcc dot gnu.org
  2024-04-11  0:32 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ibhagat at gcc dot gnu.org @ 2024-04-09 21:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Indu Bhagat <ibhagat at gcc dot gnu.org> ---
Hmm, thanks. Using sorry in some cases will be a viable option.

For this specific case though, I am thinking emitting CTF_K_UNKNOWN instead
should be okay.  We have precedent in CTF generation in GCC where if a type is
not representable, we use a type of kind CTF_K_UNKNOWN instead.

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

* [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with _BitInt > 255 in a struct and -gctf1
  2023-12-06 10:51 [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1 iamanonymous.cs at gmail dot com
                   ` (4 preceding siblings ...)
  2024-04-09 21:18 ` ibhagat at gcc dot gnu.org
@ 2024-04-11  0:32 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-11  0:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Indu Bhagat <ibhagat@gcc.gnu.org>:

https://gcc.gnu.org/g:5c869aa8a4538b218d9e59de6c96133971e7b965

commit r14-9906-g5c869aa8a4538b218d9e59de6c96133971e7b965
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date:   Wed Apr 10 17:27:52 2024 -0700

    ctf: fix PR debug/112878

    PR debug/112878: ICE: in ctf_add_slice, at ctfc.cc:499 with
    _BitInt > 255 in a struct and -gctf1

    The CTF generation in GCC does not have a mechanism to roll-back an
    already added type.  In this testcase presented in the PR, we hit a
    representation limit in CTF slices (for a member of a struct) and ICE,
    after the type for struct (CTF_K_STRUCT) has already been added to the
    container.

    To exit gracefully instead, we now check for both the offset and size of
    the bitfield to be explicitly <= 255.  If the check fails, we emit the
    member with type CTF_K_UNKNOWN.  Note that, the value 255 stems from the
    existing binutils libctf checks which were motivated to guard against
    malformed inputs.

    Although it is not accurate to say that this is a CTF representation
    limit, mark the code with TBD_CTF_REPRESENTATION_LIMIT for now so that
    this can be taken care of with the next format version bump, when
    libctf's checks for the slice data can be lifted as well.

    gcc/ChangeLog:
            PR debug/112878
            * dwarf2ctf.cc (gen_ctf_sou_type): Check for conditions before
            call to ctf_add_slice.  Use CTF_K_UNKNOWN type if fail.

    gcc/testsuite/ChangeLog:
            PR debug/112878
            * gcc.dg/debug/ctf/ctf-bitfields-5.c: New test.

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

end of thread, other threads:[~2024-04-11  0:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06 10:51 [Bug debug/112878] New: ICE: in ctf_add_slice, at ctfc.cc:499 with -std=c23 -gctf1 iamanonymous.cs at gmail dot com
2024-01-19 15:57 ` [Bug c/112878] " zsojka at seznam dot cz
2024-01-20  9:02 ` [Bug debug/112878] " pinskia at gcc dot gnu.org
2024-04-09 18:34 ` [Bug debug/112878] ICE: in ctf_add_slice, at ctfc.cc:499 with _BitInt > 255 in a struct and -gctf1 ibhagat at gcc dot gnu.org
2024-04-09 18:44 ` pinskia at gcc dot gnu.org
2024-04-09 21:18 ` ibhagat at gcc dot gnu.org
2024-04-11  0:32 ` cvs-commit 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).