public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
@ 2022-12-20 20:27 james.hilliard1 at gmail dot com
  2022-12-20 20:30 ` [Bug target/108189] " pinskia at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: james.hilliard1 at gmail dot com @ 2022-12-20 20:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108189
           Summary: anonymous struct declared inside parameter list will
                    not be visible outside of this definition or
                    declaration
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: james.hilliard1 at gmail dot com
  Target Milestone: ---

I'm seeing this error which does not occur in llvm for a bpf
test(btf_dump_test_case_bitfields.c) in bpf-next:

progs/btf_dump_test_case_bitfields.c:85:7: error: anonymous struct declared
inside parameter list will not be visible outside of this definition or
declaration [-Werror]
   85 | int f(struct {
      |       ^~~~~~

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
@ 2022-12-20 20:30 ` pinskia at gcc dot gnu.org
  2022-12-20 20:40 ` james.hilliard1 at gmail dot com
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-20 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The error is correct at least for C before C23.

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
  2022-12-20 20:30 ` [Bug target/108189] " pinskia at gcc dot gnu.org
@ 2022-12-20 20:40 ` james.hilliard1 at gmail dot com
  2022-12-20 20:41 ` pinskia at gcc dot gnu.org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: james.hilliard1 at gmail dot com @ 2022-12-20 20:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from James Hilliard <james.hilliard1 at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> The error is correct at least for C before C23.

Hmm, seeing it with -std=gnu2x passed still:
/home/buildroot/opt/cross/bin/bpf-gcc  -g -Werror -D__TARGET_ARCH_x86
-mlittle-endian
-I/home/buildroot/bpf-next/tools/bpf/resolve_btfids/libbpf/include
-I/home/buildroot/bpf-next/tools/testing/selftests/bpf/tools/include
-I/home/buildroot/bpf-next/tools/testing/selftests/bpf
-I/home/buildroot/bpf-next/tools/include/uapi
-I/home/buildroot/bpf-next/tools/testing/selftests/usr/include -gbtf -mco-re
-Wno-error=attributes -Wno-error=address-of-packed-member
-Wno-compare-distinct-pointer-types -std=gnu2x -idirafter
/usr/lib/gcc/x86_64-linux-gnu/11/include -idirafter /usr/local/include
-idirafter /usr/include/x86_64-linux-gnu -idirafter /usr/include  -nostdinc -O2
-c progs/btf_dump_test_case_bitfields.c -mcpu=v3 -o
/home/buildroot/bpf-next/tools/testing/selftests/bpf/bpf_gcc/btf_dump_test_case_bitfields.bpf.o
progs/btf_dump_test_case_bitfields.c:85:7: error: anonymous struct declared
inside parameter list will not be visible outside of this definition or
declaration [-Werror]
   85 | int f(struct {
      |       ^~~~~~

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
  2022-12-20 20:30 ` [Bug target/108189] " pinskia at gcc dot gnu.org
  2022-12-20 20:40 ` james.hilliard1 at gmail dot com
@ 2022-12-20 20:41 ` pinskia at gcc dot gnu.org
  2022-12-20 20:46 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-20 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC does not implement all of C2X yet.

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-12-20 20:41 ` pinskia at gcc dot gnu.org
@ 2022-12-20 20:46 ` pinskia at gcc dot gnu.org
  2022-12-20 20:46 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-20 20:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also Clang does not implement this warning at all.

It is a bug in bpf-next really.

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (3 preceding siblings ...)
  2022-12-20 20:46 ` pinskia at gcc dot gnu.org
@ 2022-12-20 20:46 ` pinskia at gcc dot gnu.org
  2022-12-20 20:48 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-20 20:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also Clang does not implement this warning at all.

It is a bug in bpf-next really.

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (4 preceding siblings ...)
  2022-12-20 20:46 ` pinskia at gcc dot gnu.org
@ 2022-12-20 20:48 ` pinskia at gcc dot gnu.org
  2022-12-20 20:56 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-20 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |MOVED

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang does not implement the warning even though it is a correct warning.
Witness:
int f(struct {int t;} b)
{
  return b.t;
}

int f1(void)
{
  return f((struct {int t;}){1});
}
Is rejected.

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (5 preceding siblings ...)
  2022-12-20 20:48 ` pinskia at gcc dot gnu.org
@ 2022-12-20 20:56 ` pinskia at gcc dot gnu.org
  2022-12-20 21:09 ` james.hilliard1 at gmail dot com
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-20 20:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes the warning is really still correct even if a closer testcase would be:
```
int f(struct {int t;} *b)
{
  return b->t;
}

int f1(void *a)
{
  return f(a);
}
```
I am actually shocked clang didn't implement this warning since there is no
type which is compatible with the typeof *b outside of function f.

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (6 preceding siblings ...)
  2022-12-20 20:56 ` pinskia at gcc dot gnu.org
@ 2022-12-20 21:09 ` james.hilliard1 at gmail dot com
  2022-12-20 21:15 ` james.hilliard1 at gmail dot com
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: james.hilliard1 at gmail dot com @ 2022-12-20 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from James Hilliard <james.hilliard1 at gmail dot com> ---
(In reply to Andrew Pinski from comment #7)
> Yes the warning is really still correct even if a closer testcase would be:
> ```
> int f(struct {int t;} *b)
> {
>   return b->t;
> }
> 
> int f1(void *a)
> {
>   return f(a);
> }
> ```
> I am actually shocked clang didn't implement this warning since there is no
> type which is compatible with the typeof *b outside of function f.

Yeah, clang with -std=gnu17 -pedantic doesn't even complain at all from the
looks of it. Does it make sense to allow disabling this specific warning in
GCC?

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (7 preceding siblings ...)
  2022-12-20 21:09 ` james.hilliard1 at gmail dot com
@ 2022-12-20 21:15 ` james.hilliard1 at gmail dot com
  2022-12-20 21:18 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: james.hilliard1 at gmail dot com @ 2022-12-20 21:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from James Hilliard <james.hilliard1 at gmail dot com> ---
(In reply to Andrew Pinski from comment #5)
> Also Clang does not implement this warning at all.
> 
> It is a bug in bpf-next really.

What would be the correct way to fix these in bpf-next?

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (8 preceding siblings ...)
  2022-12-20 21:15 ` james.hilliard1 at gmail dot com
@ 2022-12-20 21:18 ` pinskia at gcc dot gnu.org
  2022-12-22 19:09 ` james.hilliard1 at gmail dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-20 21:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to James Hilliard from comment #8) 
> Yeah, clang with -std=gnu17 -pedantic doesn't even complain at all from the
> looks of it. Does it make sense to allow disabling this specific warning in
> GCC?

No it does not make sense at all to disable this specific warning; maybe
request clang implement the warning too.

> What would be the correct way to fix these in bpf-next?

Move the struct definition outside of the function definition? You could ask
the bpf mailing list of what is the fix they would like to see for this
questionable code.

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (9 preceding siblings ...)
  2022-12-20 21:18 ` pinskia at gcc dot gnu.org
@ 2022-12-22 19:09 ` james.hilliard1 at gmail dot com
  2024-05-07  2:08 ` dxu at dxuuu dot xyz
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: james.hilliard1 at gmail dot com @ 2022-12-22 19:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from James Hilliard <james.hilliard1 at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> The error is correct at least for C before C23.

Can you clarify where exactly in the C23 specification that this will be
allowed?

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (10 preceding siblings ...)
  2022-12-22 19:09 ` james.hilliard1 at gmail dot com
@ 2024-05-07  2:08 ` dxu at dxuuu dot xyz
  2024-05-07  6:34 ` jemarch at gcc dot gnu.org
  2024-05-07 14:44 ` dxu at dxuuu dot xyz
  13 siblings, 0 replies; 15+ messages in thread
From: dxu at dxuuu dot xyz @ 2024-05-07  2:08 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Xu <dxu at dxuuu dot xyz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dxu at dxuuu dot xyz

--- Comment #12 from Daniel Xu <dxu at dxuuu dot xyz> ---
I was fighting this warning as well (for bpftrace tests).

I believe the part of the C23 standard being referred
to is https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3037.pdf

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (11 preceding siblings ...)
  2024-05-07  2:08 ` dxu at dxuuu dot xyz
@ 2024-05-07  6:34 ` jemarch at gcc dot gnu.org
  2024-05-07 14:44 ` dxu at dxuuu dot xyz
  13 siblings, 0 replies; 15+ messages in thread
From: jemarch at gcc dot gnu.org @ 2024-05-07  6:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Jose E. Marchesi <jemarch at gcc dot gnu.org> ---
In bpf-next we are passing -Wno-error for the particular BPF selftests that use
this construct:

progs/btf_dump_test_case_bitfields.c-CFLAGS := -Wno-error
progs/btf_dump_test_case_namespacing.c-CFLAGS := -Wno-error
progs/btf_dump_test_case_packing.c-CFLAGS := -Wno-error
progs/btf_dump_test_case_padding.c-CFLAGS := -Wno-error
progs/btf_dump_test_case_syntax.c-CFLAGS := -Wno-error

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

* [Bug target/108189] anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
  2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
                   ` (12 preceding siblings ...)
  2024-05-07  6:34 ` jemarch at gcc dot gnu.org
@ 2024-05-07 14:44 ` dxu at dxuuu dot xyz
  13 siblings, 0 replies; 15+ messages in thread
From: dxu at dxuuu dot xyz @ 2024-05-07 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Daniel Xu <dxu at dxuuu dot xyz> ---
Yeah, I saw that. But that only makes the build not
fail right? For bpftrace we are trying hard to be
warning-free.

FWIW I tried adding `-std=gnu2x` and it didn't help.

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

end of thread, other threads:[~2024-05-07 14:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 20:27 [Bug target/108189] New: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration james.hilliard1 at gmail dot com
2022-12-20 20:30 ` [Bug target/108189] " pinskia at gcc dot gnu.org
2022-12-20 20:40 ` james.hilliard1 at gmail dot com
2022-12-20 20:41 ` pinskia at gcc dot gnu.org
2022-12-20 20:46 ` pinskia at gcc dot gnu.org
2022-12-20 20:46 ` pinskia at gcc dot gnu.org
2022-12-20 20:48 ` pinskia at gcc dot gnu.org
2022-12-20 20:56 ` pinskia at gcc dot gnu.org
2022-12-20 21:09 ` james.hilliard1 at gmail dot com
2022-12-20 21:15 ` james.hilliard1 at gmail dot com
2022-12-20 21:18 ` pinskia at gcc dot gnu.org
2022-12-22 19:09 ` james.hilliard1 at gmail dot com
2024-05-07  2:08 ` dxu at dxuuu dot xyz
2024-05-07  6:34 ` jemarch at gcc dot gnu.org
2024-05-07 14:44 ` dxu at dxuuu dot xyz

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