public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend
@ 2022-12-02 13:28 siddhesh at gcc dot gnu.org
  2022-12-02 14:44 ` [Bug c/107951] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: siddhesh at gcc dot gnu.org @ 2022-12-02 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107951
           Summary: Invalid flexible array use not detected in nested
                    structs by the C frontend
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: siddhesh at gcc dot gnu.org
  Target Milestone: ---

The following program:

typedef struct {
  char pad;
  char data[];
} F2;

typedef struct {
  F2 flex;
  unsigned pad;
} S2;

#define NULL (void *) 0

__SIZE_TYPE__
nested_flexarray (__SIZE_TYPE__ n)
{
  S2 *p = __builtin_malloc (n);

  return __builtin_dynamic_object_size (p->flex.data, 1);
}

ends up treating data[] as a zero sized array in C instead of flagging an
error.  This is correctly handled in the C++ driver.

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
@ 2022-12-02 14:44 ` rguenth at gcc dot gnu.org
  2022-12-02 15:38 ` qinzhao at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-02 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
                 CC|                            |jsm28 at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
> ./cc1 -quiet t.c -pedantic-errors
t.c:7:6: error: invalid use of structure with flexible array member
[-Wpedantic]
    7 |   F2 flex;
      |      ^~~~

so this is supposedly a GCC extension, treating [] as [0] in this context?

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
  2022-12-02 14:44 ` [Bug c/107951] " rguenth at gcc dot gnu.org
@ 2022-12-02 15:38 ` qinzhao at gcc dot gnu.org
  2022-12-02 15:47 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-12-02 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

qinzhao at gcc dot gnu.org changed:

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

--- Comment #2 from qinzhao at gcc dot gnu.org ---
(In reply to Richard Biener from comment #1)
> > ./cc1 -quiet t.c -pedantic-errors
> t.c:7:6: error: invalid use of structure with flexible array member
> [-Wpedantic]
>     7 |   F2 flex;
>       |      ^~~~
> 
> so this is supposedly a GCC extension, treating [] as [0] in this context?

I found this in the gcc doc:

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html#Zero-Length

"A structure containing a flexible array member, or a union containing such a
structure (possibly recursively), may not be a member of a structure or an
element of an array. (However, these uses are permitted by GCC as extensions.)"

Looks like this usage is permitted by GCC extensions.

However, cannot find the details in the doc on how GCC treat these usage.

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
  2022-12-02 14:44 ` [Bug c/107951] " rguenth at gcc dot gnu.org
  2022-12-02 15:38 ` qinzhao at gcc dot gnu.org
@ 2022-12-02 15:47 ` pinskia at gcc dot gnu.org
  2022-12-02 15:50 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-02 15:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
r0-44662-g2984fe64968ad7 added that documentation.
PR 15749 shows that at one point there was code floating around (glibc?) that
uses the extension (_G_iconv_t).

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-12-02 15:47 ` pinskia at gcc dot gnu.org
@ 2022-12-02 15:50 ` pinskia at gcc dot gnu.org
  2022-12-02 16:36 ` siddhesh at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-02 15:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=77650

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is a duplicate of bug 77650. See there for more details.

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-12-02 15:50 ` pinskia at gcc dot gnu.org
@ 2022-12-02 16:36 ` siddhesh at gcc dot gnu.org
  2022-12-02 16:51 ` qinzhao at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: siddhesh at gcc dot gnu.org @ 2022-12-02 16:36 UTC (permalink / raw)
  To: gcc-bugs

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

Siddhesh Poyarekar <siddhesh at gcc dot gnu.org> changed:

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

--- Comment #5 from Siddhesh Poyarekar <siddhesh at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> r0-44662-g2984fe64968ad7 added that documentation.
> PR 15749 shows that at one point there was code floating around (glibc?)
> that uses the extension (_G_iconv_t).

Yeah but it doesn't address bug 77650, which I agree that this is a duplicate
of.  Thanks for pointing out!

*** This bug has been marked as a duplicate of bug 77650 ***

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-12-02 16:36 ` siddhesh at gcc dot gnu.org
@ 2022-12-02 16:51 ` qinzhao at gcc dot gnu.org
  2022-12-02 16:55 ` jakub at gcc dot gnu.org
  2022-12-02 17:01 ` qinzhao at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-12-02 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from qinzhao at gcc dot gnu.org ---
after reading the history, my understanding is:

 this gcc extension is added as a workaround to build glibc since glibc source
code has such usage of flexible array members;

my question is: why not changing the glibc source code instead? then we don't
need such workaround in GCC?

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-12-02 16:51 ` qinzhao at gcc dot gnu.org
@ 2022-12-02 16:55 ` jakub at gcc dot gnu.org
  2022-12-02 17:01 ` qinzhao at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-02 16:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to qinzhao from comment #6)
> after reading the history, my understanding is:
> 
>  this gcc extension is added as a workaround to build glibc since glibc
> source code has such usage of flexible array members;
> 
> my question is: why not changing the glibc source code instead? then we
> don't need such workaround in GCC?

Because after all those years, you don't really know if it is just glibc (which
likely doesn't do that anymore), but many other programs in the wild.

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

* [Bug c/107951] Invalid flexible array use not detected in nested structs by the C frontend
  2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-12-02 16:55 ` jakub at gcc dot gnu.org
@ 2022-12-02 17:01 ` qinzhao at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-12-02 17:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from qinzhao at gcc dot gnu.org ---
(In reply to Jakub Jelinek from comment #7)
> 
> Because after all those years, you don't really know if it is just glibc
> (which likely doesn't do that anymore), but many other programs in the wild.

Yes, Unfortunately that's the case. thanks.

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

end of thread, other threads:[~2022-12-02 17:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02 13:28 [Bug c/107951] New: Invalid flexible array use not detected in nested structs by the C frontend siddhesh at gcc dot gnu.org
2022-12-02 14:44 ` [Bug c/107951] " rguenth at gcc dot gnu.org
2022-12-02 15:38 ` qinzhao at gcc dot gnu.org
2022-12-02 15:47 ` pinskia at gcc dot gnu.org
2022-12-02 15:50 ` pinskia at gcc dot gnu.org
2022-12-02 16:36 ` siddhesh at gcc dot gnu.org
2022-12-02 16:51 ` qinzhao at gcc dot gnu.org
2022-12-02 16:55 ` jakub at gcc dot gnu.org
2022-12-02 17:01 ` qinzhao 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).