public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/116726] New: compiler segfault when using certain struct redefinitions
@ 2024-09-15 18:42 himehaieto at gmail dot com
  2024-09-15 18:46 ` [Bug c/116726] " peter0x44 at disroot dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: himehaieto at gmail dot com @ 2024-09-15 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116726
           Summary: compiler segfault when using certain struct
                    redefinitions
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: himehaieto at gmail dot com
  Target Milestone: ---

Created attachment 59116
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59116&action=edit
preprocessed reproducer code

I am seeing an ICE segfault with certain uses of C23 struct redefinitions.  See
the attached for reproducer code and below for additional information.

`uname -a`:
Linux votocon 4.19.0-21-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
GNU/Linux

`lsb_release -a`:
Distributor ID: Devuan
Description:    Devuan GNU/Linux 5 (daedalus)
Release:        5
Codename:       daedalus

gcc configure options:
../../configure --prefix=/opt/gcc/14.2.0 --enable-lto

compiler command/options:
gcc --std=c23 list_test.c

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

* [Bug c/116726] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
@ 2024-09-15 18:46 ` peter0x44 at disroot dot org
  2024-09-15 18:50 ` himehaieto at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: peter0x44 at disroot dot org @ 2024-09-15 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

Peter Damianov <peter0x44 at disroot dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter0x44 at disroot dot org

--- Comment #1 from Peter Damianov <peter0x44 at disroot dot org> ---
Confirmed.

Weirdly, I cannot reproduce this on mingw hosts.
I am not sure why.

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

* [Bug c/116726] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
  2024-09-15 18:46 ` [Bug c/116726] " peter0x44 at disroot dot org
@ 2024-09-15 18:50 ` himehaieto at gmail dot com
  2024-09-15 18:51 ` [Bug c/116726] [14/15 Regression] " pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: himehaieto at gmail dot com @ 2024-09-15 18:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Hime Haieto <himehaieto at gmail dot com> ---
Actually, I had also tried using the -freport-bug option like the ICE had
advised, but it failed with the message:

"The bug is not reproducible, so it is likely a hardware or OS problem."

It seems to fail for all current versions on godbolt.

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

* [Bug c/116726] [14/15 Regression] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
  2024-09-15 18:46 ` [Bug c/116726] " peter0x44 at disroot dot org
  2024-09-15 18:50 ` himehaieto at gmail dot com
@ 2024-09-15 18:51 ` pinskia at gcc dot gnu.org
  2024-09-15 20:12 ` muecker at gwdg dot de
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-09-15 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|compiler segfault when      |[14/15 Regression] compiler
                   |using certain struct        |segfault when using certain
                   |redefinitions               |struct redefinitions
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-09-15
           Keywords|                            |ice-on-valid-code
   Target Milestone|---                         |14.3
                 CC|                            |muecker at gwdg dot de

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Reduced slightly:
```
struct s1 {
  int f1;
};
struct s2 {
  int f2;
};
struct s1 f(struct s2 *);
struct s1 {
  int f1;
};
struct s2 {
  int f2;
};
struct s1 f(struct s2 *);
```

I think this is valid due to change in C23 tag compability.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3003.pdf .

Clang does not implement the C23 tag compatibility rules yet.

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

* [Bug c/116726] [14/15 Regression] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
                   ` (2 preceding siblings ...)
  2024-09-15 18:51 ` [Bug c/116726] [14/15 Regression] " pinskia at gcc dot gnu.org
@ 2024-09-15 20:12 ` muecker at gwdg dot de
  2024-09-17 10:13 ` muecker at gwdg dot de
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: muecker at gwdg dot de @ 2024-09-15 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Martin Uecker <muecker at gwdg dot de> ---

I will look at this.

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

* [Bug c/116726] [14/15 Regression] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
                   ` (3 preceding siblings ...)
  2024-09-15 20:12 ` muecker at gwdg dot de
@ 2024-09-17 10:13 ` muecker at gwdg dot de
  2024-09-17 14:03 ` peter0x44 at disroot dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: muecker at gwdg dot de @ 2024-09-17 10:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Martin Uecker <muecker at gwdg dot de> ---

Fix being tested.

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 58b2724b39e..ba6d96d26b2 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -1686,8 +1686,11 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree
t2,
            data->anon_field = !DECL_NAME (s1);
            data->pointedto = false;

+           const struct tagged_tu_seen_cache *cache = data->cache;
            data->cache = &entry;
-           if (!comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2), data))
+           bool ret = comptypes_internal (TREE_TYPE (s1), TREE_TYPE (s2),
data);
+           data->cache = cache;
+           if (!ret)
              return false;

            tree st1 = TYPE_SIZE (TREE_TYPE (s1));

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

* [Bug c/116726] [14/15 Regression] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
                   ` (4 preceding siblings ...)
  2024-09-17 10:13 ` muecker at gwdg dot de
@ 2024-09-17 14:03 ` peter0x44 at disroot dot org
  2024-09-17 14:33 ` muecker at gwdg dot de
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: peter0x44 at disroot dot org @ 2024-09-17 14:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Peter Damianov <peter0x44 at disroot dot org> ---
Another testcase:
not an ICE, but I think rejects-valid
```
typedef void f(struct s1);
struct s1 {
  int f1;
};
typedef void f(struct s1);
```

<source>:5:14: error: conflicting types for 'f'; have 'void(struct s1)'
    5 | typedef void f(struct s1);
      |              ^
<source>:1:14: note: previous declaration of 'f' with type 'f' {aka
'void(struct s1)'}
    1 | typedef void f(struct s1);
      |              ^

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

* [Bug c/116726] [14/15 Regression] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
                   ` (5 preceding siblings ...)
  2024-09-17 14:03 ` peter0x44 at disroot dot org
@ 2024-09-17 14:33 ` muecker at gwdg dot de
  2024-09-17 14:34 ` muecker at gwdg dot de
  2024-09-20 20:54 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: muecker at gwdg dot de @ 2024-09-17 14:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Martin Uecker <muecker at gwdg dot de> ---
(In reply to Peter Damianov from comment #6)
> Another testcase:
> not an ICE, but I think rejects-valid
> ```
> typedef void f(struct s1);
> struct s1 {
>   int f1;
> };
> typedef void f(struct s1);
> ```
> 
> <source>:5:14: error: conflicting types for 'f'; have 'void(struct s1)'
>     5 | typedef void f(struct s1);
>       |              ^
> <source>:1:14: note: previous declaration of 'f' with type 'f' {aka
> 'void(struct s1)'}
>     1 | typedef void f(struct s1);
>       |              ^

This is the same as:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116728

But I think the behavior is correct. See the discussion there.

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

* [Bug c/116726] [14/15 Regression] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
                   ` (6 preceding siblings ...)
  2024-09-17 14:33 ` muecker at gwdg dot de
@ 2024-09-17 14:34 ` muecker at gwdg dot de
  2024-09-20 20:54 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: muecker at gwdg dot de @ 2024-09-17 14:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Martin Uecker <muecker at gwdg dot de> ---
PATCH: https://gcc.gnu.org/pipermail/gcc-patches/2024-September/663123.html

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

* [Bug c/116726] [14/15 Regression] compiler segfault when using certain struct redefinitions
  2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
                   ` (7 preceding siblings ...)
  2024-09-17 14:34 ` muecker at gwdg dot de
@ 2024-09-20 20:54 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-09-20 20:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:

https://gcc.gnu.org/g:9227a64495d5594613604573b72422e8e3722fc5

commit r15-3745-g9227a64495d5594613604573b72422e8e3722fc5
Author: Martin Uecker <uecker@tugraz.at>
Date:   Tue Sep 17 11:37:29 2024 +0200

    c: fix crash when checking for compatibility of structures [PR116726]

    When checking for compatibility of structure or union types in
    tagged_types_tu_compatible_p, restore the old value of the pointer to
    the top of the temporary cache after recursively calling comptypes_internal
    when looping over the members of a structure of union.  While the next
    iteration of the loop overwrites the pointer, I missed the fact that it can
    be accessed again when types of function arguments are compared as part
    of recursive type checking and the function is entered again.

            PR c/116726

    gcc/c/ChangeLog:

            * c-typeck.cc (tagged_types_tu_compatible_p): Restore value
            of the cache after recursing into comptypes_internal.

    gcc/testsuite/ChangeLog:

            * gcc.dg/pr116726.c: New test.

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

end of thread, other threads:[~2024-09-20 20:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-15 18:42 [Bug c/116726] New: compiler segfault when using certain struct redefinitions himehaieto at gmail dot com
2024-09-15 18:46 ` [Bug c/116726] " peter0x44 at disroot dot org
2024-09-15 18:50 ` himehaieto at gmail dot com
2024-09-15 18:51 ` [Bug c/116726] [14/15 Regression] " pinskia at gcc dot gnu.org
2024-09-15 20:12 ` muecker at gwdg dot de
2024-09-17 10:13 ` muecker at gwdg dot de
2024-09-17 14:03 ` peter0x44 at disroot dot org
2024-09-17 14:33 ` muecker at gwdg dot de
2024-09-17 14:34 ` muecker at gwdg dot de
2024-09-20 20:54 ` 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).