public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
@ 2020-09-02 19:23 redi at gcc dot gnu.org
  2020-09-02 20:44 ` [Bug c++/96905] " mpolacek at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-02 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96905
           Summary: ICE with consteval function: internal compiler error:
                    in cp_gimplify_expr, at cp/cp-gimplify.c:827
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

template<typename Rep>
struct duration
{
  static consteval int
  gcd(int m, int n) noexcept
  {
    while (m != 0 && n != 0)
    {
      int rem = m % n;
      m = n;
      n = rem;
    }
    return m + n;
  }
};

template class duration<int>;

Compiled with -std=gnu++20 this ICEs:

ice.C: In static member function 'static consteval int duration<Rep>::gcd(int,
int) [with Rep = int]':
ice.C:7:5: internal compiler error: in cp_gimplify_expr, at
cp/cp-gimplify.c:827
    7 |     while (m != 0 && n != 0)
      |     ^~~~~
0x603457 cp_gimplify_expr(tree_node**, gimple**, gimple**)
        /home/jwakely/src/gcc/gcc/gcc/cp/cp-gimplify.c:827
0xd3f160 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:13571
0xd435c6 gimplify_stmt(tree_node**, gimple**)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:6822
0xd40e43 gimplify_statement_list
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:1856
0xd40e43 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:14106
0xd435c6 gimplify_stmt(tree_node**, gimple**)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:6822
0xd44291 gimplify_bind_expr
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:1411
0xd40209 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:13863
0xd4dcdc gimplify_stmt(tree_node**, gimple**)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:6822
0xd4dcdc gimplify_and_add(tree_node*, gimple**)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:486
0x8de1d3 gimplify_must_not_throw_expr
        /home/jwakely/src/gcc/gcc/gcc/cp/cp-gimplify.c:577
0x8de1d3 cp_gimplify_expr(tree_node**, gimple**, gimple**)
        /home/jwakely/src/gcc/gcc/gcc/cp/cp-gimplify.c:717
0xd3f160 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:13571
0xd58ac7 gimplify_stmt(tree_node**, gimple**)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:6822
0xd58ac7 gimplify_body(tree_node*, bool)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:14898
0xd58efd gimplify_function_tree(tree_node*)
        /home/jwakely/src/gcc/gcc/gcc/gimplify.c:15052
0xb9f997 cgraph_node::analyze()
        /home/jwakely/src/gcc/gcc/gcc/cgraphunit.c:671
0xba29b7 analyze_functions
        /home/jwakely/src/gcc/gcc/gcc/cgraphunit.c:1235
0xba357d symbol_table::finalize_compilation_unit()
        /home/jwakely/src/gcc/gcc/gcc/cgraphunit.c:2991
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

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

* [Bug c++/96905] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
@ 2020-09-02 20:44 ` mpolacek at gcc dot gnu.org
  2020-09-02 20:48 ` mpolacek at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-09-02 20:44 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-09-02

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.  Started with r277733 -- the introduction of consteval.

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

* [Bug c++/96905] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
  2020-09-02 20:44 ` [Bug c++/96905] " mpolacek at gcc dot gnu.org
@ 2020-09-02 20:48 ` mpolacek at gcc dot gnu.org
  2020-09-02 21:07 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-09-02 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
It looks like we've never cp_genericized the consteval function.

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

* [Bug c++/96905] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
  2020-09-02 20:44 ` [Bug c++/96905] " mpolacek at gcc dot gnu.org
  2020-09-02 20:48 ` mpolacek at gcc dot gnu.org
@ 2020-09-02 21:07 ` jakub at gcc dot gnu.org
  2020-09-03 10:47 ` [Bug c++/96905] [10/11 Regression] " jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-02 21:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Yeah, we certainly never want to genericize them.

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

* [Bug c++/96905] [10/11 Regression] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-09-02 21:07 ` jakub at gcc dot gnu.org
@ 2020-09-03 10:47 ` jakub at gcc dot gnu.org
  2020-09-03 19:26 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-03 10:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.3
            Summary|ICE with consteval          |[10/11 Regression] ICE with
                   |function: internal compiler |consteval function:
                   |error: in cp_gimplify_expr, |internal compiler error: in
                   |at cp/cp-gimplify.c:827     |cp_gimplify_expr, at
                   |                            |cp/cp-gimplify.c:827
                 CC|                            |jason at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The problem is in
#0  cgraph_node::create (decl=<function_decl 0x7fffea93e900 gcd>) at
../../gcc/cgraph.c:508
#1  0x0000000000f2b79c in cgraph_node::get_create (decl=<function_decl
0x7fffea93e900 gcd>) at ../../gcc/cgraph.c:541
#2  0x0000000000b0a700 in mark_needed (decl=<function_decl 0x7fffea93e900 gcd>)
at ../../gcc/cp/decl2.c:2181
#3  0x0000000000cb25b6 in mark_decl_instantiated (result=<function_decl
0x7fffea93e900 gcd>, extern_p=0) at ../../gcc/cp/pt.c:23893
#4  0x0000000000cb6b35 in do_type_instantiation (t=<record_type 0x7fffea93b930
S>, storage=<tree 0x0>, complain=1) at ../../gcc/cp/pt.c:25041
#5  0x0000000000befb77 in cp_parser_explicit_instantiation
(parser=0x7fffea8238e8) at ../../gcc/cp/parser.c:17588

for DECL_IMMEDIATE_FUNCTION_P FUNCTION_DECLs, we really don't want to register
them with the middle-end.  The big question is, do we really care about
explicit vs. implicit instantiation for them.  I mean, if something calls the
consteval function, it doesn't really matter if we instantiate them implicitly
or explicitly.  Where it could matter is diagnostics, if the consteval function
is never called or never called instantiated with a particular template
arguments, and its definition is invalid with those template arguments (but not
invalid to be rejected when parsed uninstantiated).
So if we care about the implicit vs. explicit instantiation of consteval,
perhaps we should just not create the cgraph node in mark_needed for
DECL_IMMEDIATE_FUNCTION_P?

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

* [Bug c++/96905] [10/11 Regression] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-09-03 10:47 ` [Bug c++/96905] [10/11 Regression] " jakub at gcc dot gnu.org
@ 2020-09-03 19:26 ` jakub at gcc dot gnu.org
  2020-10-12 12:25 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-03 19:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Tried
--- gcc/cp/semantics.c.jj       2020-09-01 09:17:50.000000000 +0200
+++ gcc/cp/semantics.c  2020-09-03 21:20:20.678830381 +0200
@@ -4517,7 +4517,7 @@ expand_or_defer_fn_1 (tree fn)
       return false;
     }

-  if (DECL_OMP_DECLARE_REDUCTION_P (fn))
+  if (DECL_IMMEDIATE_FUNCTION_P (fn) || DECL_OMP_DECLARE_REDUCTION_P (fn))
     return false;

   return true;
--- gcc/cp/decl2.c.jj   2020-07-28 15:39:09.780759362 +0200
+++ gcc/cp/decl2.c      2020-09-03 21:23:15.973278453 +0200
@@ -2172,7 +2172,7 @@ void
 mark_needed (tree decl)
 {
   TREE_USED (decl) = 1;
-  if (TREE_CODE (decl) == FUNCTION_DECL)
+  if (TREE_CODE (decl) == FUNCTION_DECL && !DECL_IMMEDIATE_FUNCTION_P (decl))
     {
       /* Extern inline functions don't become needed when referenced.
         If we know a method will be emitted in other TU and no new
--- gcc/cp/pt.c.jj      2020-09-01 09:17:28.042110726 +0200
+++ gcc/cp/pt.c 2020-09-03 21:14:14.497159429 +0200
@@ -23891,8 +23891,10 @@ mark_decl_instantiated (tree result, int
     {
       mark_definable (result);
       mark_needed (result);
+      if (DECL_IMMEDIATE_FUNCTION_P (result))
+       ;
       /* Always make artificials weak.  */
-      if (DECL_ARTIFICIAL (result) && flag_weak)
+      else if (DECL_ARTIFICIAL (result) && flag_weak)
        comdat_linkage (result);
       /* For WIN32 we also want to put explicit instantiations in
         linkonce sections.  */
but that is still not enough, the above are just some hacks to avoid creating
cgraph nodes for immediate functions, but e.g. c_parse_final_cleanups still
creates them.

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

* [Bug c++/96905] [10/11 Regression] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2020-09-03 19:26 ` jakub at gcc dot gnu.org
@ 2020-10-12 12:25 ` rguenth at gcc dot gnu.org
  2021-02-09  1:52 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-12 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/96905] [10/11 Regression] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2020-10-12 12:25 ` rguenth at gcc dot gnu.org
@ 2021-02-09  1:52 ` cvs-commit at gcc dot gnu.org
  2021-02-11 23:10 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-09  1:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:57d705da0b98f5d398c4b8f9bd76fe8ad98e13bc

commit r11-7143-g57d705da0b98f5d398c4b8f9bd76fe8ad98e13bc
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Feb 8 17:16:14 2021 -0500

    c++: consteval and explicit instantiation [PR96905]

    Normally, an explicit instantiation means we want to write out the
    instantiation.  But not for a consteval function.

    gcc/cp/ChangeLog:

            PR c++/96905
            * pt.c (mark_decl_instantiated): Exit early if consteval.

    gcc/testsuite/ChangeLog:

            PR c++/96905
            * g++.dg/cpp2a/consteval-expinst1.C: New test.

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

* [Bug c++/96905] [10/11 Regression] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-02-09  1:52 ` cvs-commit at gcc dot gnu.org
@ 2021-02-11 23:10 ` jason at gcc dot gnu.org
  2021-02-12  2:30 ` cvs-commit at gcc dot gnu.org
  2021-02-12  2:48 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2021-02-11 23:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

* [Bug c++/96905] [10/11 Regression] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2021-02-11 23:10 ` jason at gcc dot gnu.org
@ 2021-02-12  2:30 ` cvs-commit at gcc dot gnu.org
  2021-02-12  2:48 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-12  2:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:86d8ecf28e6c20b3e6866a5b1551a339edc8d14d

commit r10-9363-g86d8ecf28e6c20b3e6866a5b1551a339edc8d14d
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Feb 8 17:16:14 2021 -0500

    c++: consteval and explicit instantiation [PR96905]

    Normally, an explicit instantiation means we want to write out the
    instantiation.  But not for a consteval function.

    gcc/cp/ChangeLog:

            PR c++/96905
            * pt.c (mark_decl_instantiated): Exit early if consteval.

    gcc/testsuite/ChangeLog:

            PR c++/96905
            * g++.dg/cpp2a/consteval-expinst1.C: New test.

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

* [Bug c++/96905] [10/11 Regression] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827
  2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2021-02-12  2:30 ` cvs-commit at gcc dot gnu.org
@ 2021-02-12  2:48 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2021-02-12  2:48 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 10.3/11.

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

end of thread, other threads:[~2021-02-12  2:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-02 19:23 [Bug c++/96905] New: ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:827 redi at gcc dot gnu.org
2020-09-02 20:44 ` [Bug c++/96905] " mpolacek at gcc dot gnu.org
2020-09-02 20:48 ` mpolacek at gcc dot gnu.org
2020-09-02 21:07 ` jakub at gcc dot gnu.org
2020-09-03 10:47 ` [Bug c++/96905] [10/11 Regression] " jakub at gcc dot gnu.org
2020-09-03 19:26 ` jakub at gcc dot gnu.org
2020-10-12 12:25 ` rguenth at gcc dot gnu.org
2021-02-09  1:52 ` cvs-commit at gcc dot gnu.org
2021-02-11 23:10 ` jason at gcc dot gnu.org
2021-02-12  2:30 ` cvs-commit at gcc dot gnu.org
2021-02-12  2:48 ` jason 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).