public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/108702] New: [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096
@ 2023-02-07 18:36 asolokha at gmx dot com
  2023-02-08 14:27 ` [Bug ipa/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc marxin at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: asolokha at gmx dot com @ 2023-02-07 18:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108702
           Summary: [13 Regression] ICE in get_partitioning_class, at
                    symtab.cc:2096
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: lto
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: asolokha at gmx dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

gcc 13.0.1 20230205 snapshot (g:d042f118798ae0648b45f97e63b0e5ab7c82c8ef) ICEs
when compiling gcc/testsuite/g++.dg/ext/stmtexpr19.C w/ -flto:

% g++-13 -flto -c gcc/testsuite/g++.dg/ext/stmtexpr19.C
during IPA pass: modref
gcc/testsuite/g++.dg/ext/stmtexpr19.C:17:12: internal compiler error: in
get_partitioning_class, at symtab.cc:2096
   17 | int main(){}
      |            ^
0x79f533 symtab_node::get_partitioning_class()
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/symtab.cc:2096
0x1061f27 lto_output_varpool_node
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/lto-cgraph.cc:631
0x1061f27 output_symtab()
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/lto-cgraph.cc:999
0x1079c3b lto_output()
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/lto-streamer-out.cc:2825
0x1107d61 write_lto
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/passes.cc:2777
0x1107d61 ipa_write_summaries_1
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/passes.cc:2841
0x1107d61 ipa_write_summaries()
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/passes.cc:2897
0xd3c19e ipa_passes
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/cgraphunit.cc:2249
0xd3c19e symbol_table::compile()
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/cgraphunit.cc:2322
0xd3ebc7 symbol_table::compile()
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/cgraphunit.cc:2302
0xd3ebc7 symbol_table::finalize_compilation_unit()
       
/var/tmp/portage/sys-devel/gcc-13.0.1_p20230205/work/gcc-13-20230205/gcc/cgraphunit.cc:2574

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

* [Bug ipa/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc
  2023-02-07 18:36 [Bug ipa/108702] New: [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 asolokha at gmx dot com
@ 2023-02-08 14:27 ` marxin at gcc dot gnu.org
  2023-02-08 16:08 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-02-08 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[13 Regression] ICE in      |[13 Regression] ICE in
                   |get_partitioning_class, at  |get_partitioning_class, at
                   |symtab.cc:2096              |symtab.cc:2096 since
                   |                            |r13-4161-g32d16fe9d7e347bc
   Last reconfirmed|                            |2023-02-08
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r13-4161-g32d16fe9d7e347bc.

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

* [Bug ipa/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc
  2023-02-07 18:36 [Bug ipa/108702] New: [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 asolokha at gmx dot com
  2023-02-08 14:27 ` [Bug ipa/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc marxin at gcc dot gnu.org
@ 2023-02-08 16:08 ` jakub at gcc dot gnu.org
  2023-02-08 17:27 ` [Bug c++/108702] " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-08 16:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Without -flto, the testcase can't be linked:
./cc1plus -quiet -std=c++23 stmtexpr19.C; g++ -o stmtexpr19{,.s}
/usr/bin/ld: /tmp/ccUo7FRx.o:(.rodata+0x0): undefined reference to
`setup()::inner'
collect2: error: ld returned 1 exit status

On the other side, when static constexpr vars are defined inside of constexpr
functions or even consteval functions, it works ok:

extern "C" void abort ();

constexpr const int *
foo ()
{
  static constexpr int a = 1;
  return &a;
}

consteval const int *
bar ()
{
  static constexpr int a = 1;
  return &a;
}

[[gnu::noipa]] void
baz (const int *x)
{
  if (*x != 1)
    abort ();
}

int
main ()
{
  constexpr const int *p = foo ();
  constexpr const int *q = bar ();
  baz (p);
  baz (q);
  if (p == q)
    abort ();
}

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

* [Bug c++/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc
  2023-02-07 18:36 [Bug ipa/108702] New: [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 asolokha at gmx dot com
  2023-02-08 14:27 ` [Bug ipa/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc marxin at gcc dot gnu.org
  2023-02-08 16:08 ` jakub at gcc dot gnu.org
@ 2023-02-08 17:27 ` jakub at gcc dot gnu.org
  2023-03-04  8:55 ` cvs-commit at gcc dot gnu.org
  2023-03-04  9:24 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-08 17:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|ipa                         |c++
           Priority|P3                          |P1
                 CC|                            |jason at gcc dot gnu.org
   Target Milestone|---                         |13.0

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Seems the reason why the above testcase works and stmtexpr19.C doesn't is in
make_rtl_for_nonlocal_decl's
7732      /* We defer emission of local statics until the corresponding
7733         DECL_EXPR is expanded.  But with constexpr its function might
never
7734         be expanded, so go ahead and tell cgraph about the variable now. 
*/
7735      defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
7736                  && !var_in_maybe_constexpr_fn (decl))
7737                 || DECL_VIRTUAL_P (decl));
while in stmtexpr19.C the inner decl isn't in constexpr fn, it is in a
statement expression inside of a static variable initializer.
The initializer evaluates to constant expression (ADDR_EXPR of inner), so the
statement expression disappears and so there is no DECL_EXPR for the inner var
nor any reasonable spot to stick it to.

I think the options are somehow discover these before they are folded away and
mark them some way, so that we don't defer_p them or otherwise arrange for
rest_of_decl_compilation to be done on them later, or, as statement expressions
are a GNU extension, simply declare that such variables in statement
expressions cause it to be not a constant expression, only DECL_EXPRs of
var_in_maybe_constexpr_fn (decl) would be accepted.
Or, do we ever need to defer_p the static variables we are talking about here
(i.e. constexpr ones or ones with constant initializers, for which it really
doesn't matter where exactly we initialize them because they are initialized in
.rodata already.

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

* [Bug c++/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc
  2023-02-07 18:36 [Bug ipa/108702] New: [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 asolokha at gmx dot com
                   ` (2 preceding siblings ...)
  2023-02-08 17:27 ` [Bug c++/108702] " jakub at gcc dot gnu.org
@ 2023-03-04  8:55 ` cvs-commit at gcc dot gnu.org
  2023-03-04  9:24 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-04  8:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:9d5730dee4f42e94004b38f8f4862c0b1f4d964c

commit r13-6473-g9d5730dee4f42e94004b38f8f4862c0b1f4d964c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Mar 4 09:51:31 2023 +0100

    c++: Don't defer local statics initialized with constant expressions
[PR108702]

    The stmtexpr19.C testcase used to be rejected as it has a static
    variable in statement expression in constexpr context, but as that
    static variable is initialized by constant expression, when P2647R1
    was implemented we agreed to make it valid.

    Now, as reported, the testcase compiles fine, but doesn't actually link
    because the static variable isn't defined anywhere, and with -flto ICEs
    because of this problem.  This is because we never
    varpool_node::finalize_decl those vars, the constant expression in which
    the DECL_EXPR is present for the static VAR_DECL is folded (constant
    evaluated) into just the address of the VAR_DECL.
    Now, similar testcase included below (do we want to include it in the
    testsuite too?) works fine, because in
    cp_finish_decl -> make_rtl_for_nonlocal_decl
    we have since PR70353 fix:
      /* We defer emission of local statics until the corresponding
         DECL_EXPR is expanded.  But with constexpr its function might never
         be expanded, so go ahead and tell cgraph about the variable now.  */
      defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
                  && !var_in_maybe_constexpr_fn (decl))
                 || DECL_VIRTUAL_P (decl));
    and so don't defer them in constexpr/consteval functions.  The following
    patch calls rest_of_decl_compilation which make_rtl_for_nonlocal_decl
didn't
    call when encountering DECL_EXPRs of such vars during constant evaluation
    if they weren't finalized yet.

    2023-03-04  Jakub Jelinek  <jakub@redhat.com>

            PR c++/108702
            * constexpr.cc: Include toplev.h.
            (cxx_eval_constant_expression) <case DECL_EXPR>: When seeing a
local
            static initialized by constant expression outside of a constexpr
            function which has been deferred by make_rtl_for_nonlocal_decl,
            call rest_of_decl_compilation on it.

            * g++.dg/ext/stmtexpr19.C: Use dg-do link rather than dg-do
compile.

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

* [Bug c++/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc
  2023-02-07 18:36 [Bug ipa/108702] New: [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 asolokha at gmx dot com
                   ` (3 preceding siblings ...)
  2023-03-04  8:55 ` cvs-commit at gcc dot gnu.org
@ 2023-03-04  9:24 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-04  9:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

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

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

end of thread, other threads:[~2023-03-04  9:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 18:36 [Bug ipa/108702] New: [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 asolokha at gmx dot com
2023-02-08 14:27 ` [Bug ipa/108702] [13 Regression] ICE in get_partitioning_class, at symtab.cc:2096 since r13-4161-g32d16fe9d7e347bc marxin at gcc dot gnu.org
2023-02-08 16:08 ` jakub at gcc dot gnu.org
2023-02-08 17:27 ` [Bug c++/108702] " jakub at gcc dot gnu.org
2023-03-04  8:55 ` cvs-commit at gcc dot gnu.org
2023-03-04  9:24 ` 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).