public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115641] New: GCC crashes on function has attribute `__attribute__((const))`
@ 2024-06-25 11:58 141242068 at smail dot nju.edu.cn
  2024-06-25 19:55 ` [Bug middle-end/115641] [11/12/13/14/15 Regression] " mpolacek at gcc dot gnu.org
  2024-06-25 19:58 ` mpolacek at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: 141242068 at smail dot nju.edu.cn @ 2024-06-25 11:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115641
           Summary: GCC crashes on function has attribute
                    `__attribute__((const))`
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 141242068 at smail dot nju.edu.cn
  Target Milestone: ---

Compiler Explorer: https://gcc.godbolt.org/z/79oo9rsxj

When compiling this with `gcc-trunk -O2`, gcc crashes.
This only occurs in trunk version, older versions like gcc-{12,13,14} are
tested to be normal.
```
#include <stdlib.h>

typedef struct {
  char hours, day, month;
  short year;
} T;

T g (void) {
  T now;
  now.hours = 1;
  now.day = 2;
  now.month = 3;
  now.year = 4;
  return now;
}

__attribute__((const)) T f (void)
{
  T virk = g ();
  return virk;
}

int main ()
{
  if (f ().hours != 1 || f ().day != 2 || f ().month != 3 || f ().year != 4)
    abort ();
  return 0;
}
```

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

* [Bug middle-end/115641] [11/12/13/14/15 Regression] GCC crashes on function has attribute `__attribute__((const))`
  2024-06-25 11:58 [Bug c/115641] New: GCC crashes on function has attribute `__attribute__((const))` 141242068 at smail dot nju.edu.cn
@ 2024-06-25 19:55 ` mpolacek at gcc dot gnu.org
  2024-06-25 19:58 ` mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-25 19:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-06-25
          Component|c                           |middle-end
            Summary|GCC crashes on function has |[11/12/13/14/15 Regression]
                   |attribute                   |GCC crashes on function has
                   |`__attribute__((const))`    |attribute
                   |                            |`__attribute__((const))`
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Target Milestone|---                         |11.5
           Priority|P3                          |P2
                 CC|                            |mpolacek at gcc dot gnu.org
           Keywords|                            |ice-on-valid-code

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.  Started with r10-3830-g853ce7c073eedf:

commit 853ce7c073eedfba1adfb63530a8bd2baa767137
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Oct 12 14:21:45 2019 +0200

    re PR middle-end/92063 (ICE in operation_could_trap_p, at tree-eh.c:2528
when compiling Python's Python/_warnings.c)

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

* [Bug middle-end/115641] [11/12/13/14/15 Regression] GCC crashes on function has attribute `__attribute__((const))`
  2024-06-25 11:58 [Bug c/115641] New: GCC crashes on function has attribute `__attribute__((const))` 141242068 at smail dot nju.edu.cn
  2024-06-25 19:55 ` [Bug middle-end/115641] [11/12/13/14/15 Regression] " mpolacek at gcc dot gnu.org
@ 2024-06-25 19:58 ` mpolacek at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-25 19:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
It's the

--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4447,8 +4447,7 @@ simple_operand_p_2 (tree exp)
 {
   enum tree_code code;

-  if (TREE_SIDE_EFFECTS (exp)
-      || tree_could_trap_p (exp))
+  if (TREE_SIDE_EFFECTS (exp) || generic_expr_could_trap_p (exp))
     return false;

   while (CONVERT_EXPR_P (exp))

change.  simple_condition_p gets

((short unsigned int) BIT_FIELD_REF <MEM <struct T> [(void *)&f ()], 16, 0> &
65535) != 513

and generic_expr_could_trap_p recurses down to tree_could_trap_p getting

MEM <struct T> [(void *)&f ()]

where we get the base which is "f ()" but DECL_SIZE_UNIT crashes on that.

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

end of thread, other threads:[~2024-06-25 19:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-25 11:58 [Bug c/115641] New: GCC crashes on function has attribute `__attribute__((const))` 141242068 at smail dot nju.edu.cn
2024-06-25 19:55 ` [Bug middle-end/115641] [11/12/13/14/15 Regression] " mpolacek at gcc dot gnu.org
2024-06-25 19:58 ` mpolacek 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).