public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types
@ 2024-09-15 21:28 himehaieto at gmail dot com
  2024-09-15 23:45 ` [Bug c/116728] " himehaieto at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: himehaieto at gmail dot com @ 2024-09-15 21:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116728
           Summary: c23 tag compatibility broken with pointers to
                    incomplete types
           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 59117
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59117&action=edit
tag-compat-pointer-bug.i

C23 changed struct tag compatibility rules to allow for structs with the same
tag and multiple non-conflicting definitions to be compatible, and for
incomplete types to be defined and established as compatible later in the
translation unit.  However, when the attached code attempts to use such an
incomplete type for a function, the compiler instead gives the familiar pre-C23
error about incompatible types (i.e., "struct foo *" vs "struct foo *").

A forward declaration at the start (i.e., struct_foo;) and/or an inline
definition of the struct within the function signature (i.e., void bar(struct
foo {int value;} *foo) {}) allow the code to compile without issues, but in
their absence it breaks.

Note that this issue has a lot more potential subtlety with language lawyer
standardese than it may seem at first, but I'm 95% sure that tag compatibility
is supposed to allow for code like the attached to work now.  See the below for
additional reproducibility 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 tag-compat-pointer-bug.c

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

* [Bug c/116728] c23 tag compatibility broken with pointers to incomplete types
  2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
@ 2024-09-15 23:45 ` himehaieto at gmail dot com
  2024-09-17  1:02 ` himehaieto at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: himehaieto at gmail dot com @ 2024-09-15 23:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Hime Haieto <himehaieto at gmail dot com> ---
This may possibly have some connections to the behaviour seen in PR116726.

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

* [Bug c/116728] c23 tag compatibility broken with pointers to incomplete types
  2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
  2024-09-15 23:45 ` [Bug c/116728] " himehaieto at gmail dot com
@ 2024-09-17  1:02 ` himehaieto at gmail dot com
  2024-09-17  5:43 ` muecker at gwdg dot de
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: himehaieto at gmail dot com @ 2024-09-17  1:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Hime Haieto <himehaieto at gmail dot com> ---
This may not actually be about pointer issues specifically - I came across
another failing test case that I think is most likely caused by the same
underlying issue:

typedef void f(struct s1);
struct s1 {
        int f1;
};
typedef void f(struct s1);

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

* [Bug c/116728] c23 tag compatibility broken with pointers to incomplete types
  2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
  2024-09-15 23:45 ` [Bug c/116728] " himehaieto at gmail dot com
  2024-09-17  1:02 ` himehaieto at gmail dot com
@ 2024-09-17  5:43 ` muecker at gwdg dot de
  2024-09-17  8:40 ` muecker at gwdg dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: muecker at gwdg dot de @ 2024-09-17  5:43 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Uecker <muecker at gwdg dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |muecker at gwdg dot de

--- Comment #3 from Martin Uecker <muecker at gwdg dot de> ---
Thank you. I think I have identified this issue already. I will submit a patch
soon.

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

* [Bug c/116728] c23 tag compatibility broken with pointers to incomplete types
  2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
                   ` (2 preceding siblings ...)
  2024-09-17  5:43 ` muecker at gwdg dot de
@ 2024-09-17  8:40 ` muecker at gwdg dot de
  2024-09-17  9:35 ` muecker at gwdg dot de
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: muecker at gwdg dot de @ 2024-09-17  8:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

Although the new example doesn't crash and the error I get seems correct to me.
What is the problem you see here?

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

* [Bug c/116728] c23 tag compatibility broken with pointers to incomplete types
  2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
                   ` (3 preceding siblings ...)
  2024-09-17  8:40 ` muecker at gwdg dot de
@ 2024-09-17  9:35 ` muecker at gwdg dot de
  2024-09-17 11:10 ` himehaieto at gmail dot com
  2024-09-17 11:14 ` himehaieto at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: muecker at gwdg dot de @ 2024-09-17  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

Sorry, mixed this up with the other bug. Here I would say the behavior is
correct as specified in ISO C23.  Note that incomplete structs could be
completed later also before ISO C23. But incomplete struct types are
incompatible to other struct types with the same tag, and the incomplete struct
declared in prototype scope is therefor incompatible to the completed one.

If you have a forward declaration so that the struct in the function prototype
refers to a file scope version that is completed later, it works.

https://godbolt.org/z/qPKcvGevM


Of course, whether the languages are perfect as specified is a different
question. 

With "typedef" there is the additional issue that "typedef" currently allows
redefinition only for identical types, not merely compatible types.

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

* [Bug c/116728] c23 tag compatibility broken with pointers to incomplete types
  2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
                   ` (4 preceding siblings ...)
  2024-09-17  9:35 ` muecker at gwdg dot de
@ 2024-09-17 11:10 ` himehaieto at gmail dot com
  2024-09-17 11:14 ` himehaieto at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: himehaieto at gmail dot com @ 2024-09-17 11:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Hime Haieto <himehaieto at gmail dot com> ---
I was pretty sure the first example in the attachment to this PR was something
that should work (less so about the second), though something something
standardese something something language lawyers.  Especially to one that
doesn't even have the final spec when various subtleties were under frequent
refinement, it can be hard to know what's supposed to be valid.  I remember
seeing some stuff suggesting that the rules would be different if it was
something completed in the same vs a different translation unit, for instance,
and I'm just a passerby to the spec.

Your point about whether the spec is perfect is well understood, but that's
what c2y/c2z/hopes/dreams are for, and what matters here is just what the spec
states rather than what it "should".  That being said, I'm normally rigid about
forward declaring *everything* even when the definition is literally one line
further down (don't judge!), so now I'm kinda wondering if there may have been
a cvise reduction issue here.

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

* [Bug c/116728] c23 tag compatibility broken with pointers to incomplete types
  2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
                   ` (5 preceding siblings ...)
  2024-09-17 11:10 ` himehaieto at gmail dot com
@ 2024-09-17 11:14 ` himehaieto at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: himehaieto at gmail dot com @ 2024-09-17 11:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Hime Haieto <himehaieto at gmail dot com> ---
Your comment about typedefs is just starting to sink in...I'll have to return
to this later though, as this is a conference week for me and it's about to
start up again soon.

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

end of thread, other threads:[~2024-09-17 11:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-15 21:28 [Bug c/116728] New: c23 tag compatibility broken with pointers to incomplete types himehaieto at gmail dot com
2024-09-15 23:45 ` [Bug c/116728] " himehaieto at gmail dot com
2024-09-17  1:02 ` himehaieto at gmail dot com
2024-09-17  5:43 ` muecker at gwdg dot de
2024-09-17  8:40 ` muecker at gwdg dot de
2024-09-17  9:35 ` muecker at gwdg dot de
2024-09-17 11:10 ` himehaieto at gmail dot com
2024-09-17 11:14 ` himehaieto at gmail dot com

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).