public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Qing Zhao <qing.zhao@oracle.com>
To: Siddhesh Poyarekar <siddhesh@gotplt.org>
Cc: "jason@redhat.com" <jason@redhat.com>,
	Richard Biener <richard.guenther@gmail.com>,
	Joseph Myers <josmyers@redhat.com>,
	"uecker@tugraz.at" <uecker@tugraz.at>,
	Kees Cook <keescook@chromium.org>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v2 3/3] Add testing cases for flexible array members in unions and alone in structures.
Date: Thu, 25 Apr 2024 14:21:20 +0000	[thread overview]
Message-ID: <C29B1490-4D94-49D4-8D5F-955B7D513B4A@oracle.com> (raw)
In-Reply-To: <eeff9032-a472-46be-91e5-5963c5bccdc6@gotplt.org>



> On Apr 25, 2024, at 10:13, Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
> 
> On 2024-04-25 10:06, Qing Zhao wrote:
>> gcc/testsuite/ChangeLog:
>> 	* c-c++-common/fam-in-union-alone-in-struct-1.c: New testcase.
>> 	* c-c++-common/fam-in-union-alone-in-struct-2.c: New testcase.
>> 	* c-c++-common/fam-in-union-alone-in-struct-3.c: New testcase.
>> ---
> 
> Sorry I should have commented sooner; could you please also add tests for __bos/__bdos for such unions and structs?

Yes, nice suggestion! Will do.

Thanks a lot.

Qing
> 
> Thanks,
> Sid
> 
>>  .../fam-in-union-alone-in-struct-1.c          | 52 +++++++++++++++++++
>>  .../fam-in-union-alone-in-struct-2.c          | 51 ++++++++++++++++++
>>  .../fam-in-union-alone-in-struct-3.c          | 36 +++++++++++++
>>  3 files changed, 139 insertions(+)
>>  create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c
>>  create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c
>>  create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c
>> diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c
>> new file mode 100644
>> index 000000000000..7d4721aa95ac
>> --- /dev/null
>> +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c
>> @@ -0,0 +1,52 @@
>> +/* testing the correct usage of flexible array members in unions
>> +   and alone in structures.  */
>> +/* { dg-do run} */
>> +/* { dg-options "-Wpedantic" } */
>> +
>> +union with_fam_1 {
>> +  int a;
>> +  int b[];  /* { dg-warning "flexible array member in union is a GCC extension" } */
>> +};
>> +
>> +union with_fam_2 {
>> +  char a;
>> +  int b[];  /* { dg-warning "flexible array member in union is a GCC extension" } */
>> +};
>> +
>> +union with_fam_3 {
>> +  char a[];  /* { dg-warning "flexible array member in union is a GCC extension" } */
>> +  /* { dg-warning "in an otherwise empty" "" { target c++ } .-1 } */
>> +  int b[];  /* { dg-warning "flexible array member in union is a GCC extension" } */
>> +};
>> +
>> +struct only_fam {
>> +  int b[];
>> +  /* { dg-warning "in a struct with no named members" "" { target c } .-1 } */
>> +  /* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */
>> +  /* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */
>> +};
>> +
>> +struct only_fam_2 {
>> +  unsigned int : 2;
>> +  unsigned int : 3;
>> +  int b[];
>> +  /* { dg-warning "in a struct with no named members" "" { target c } .-1 } */
>> +  /* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */
>> +  /* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */
>> +};
>> +
>> +int main ()
>> +{
>> +  if (sizeof (union with_fam_1) != sizeof (int))
>> +    __builtin_abort ();
>> +  if (sizeof (union with_fam_2) != __alignof__ (int))
>> +    __builtin_abort ();
>> +  if (sizeof (union with_fam_3) != 0)
>> +    __builtin_abort ();
>> +  if (sizeof (struct only_fam) != 0)
>> +    __builtin_abort ();
>> +  if (sizeof (struct only_fam_2) != sizeof (int))
>> +    __builtin_abort ();
>> +  return 0;
>> +}
>> +
>> diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c
>> new file mode 100644
>> index 000000000000..3743f9e7dac5
>> --- /dev/null
>> +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c
>> @@ -0,0 +1,51 @@
>> +/* testing the correct usage of flexible array members in unions
>> +   and alone in structures: initialization  */
>> +/* { dg-do run} */
>> +/* { dg-options "-O2" } */
>> +
>> +union with_fam_1 {
>> +  int a;
>> +  int b[];
>> +} with_fam_1_v = {.b = {1, 2, 3, 4}};
>> +
>> +union with_fam_2 {
>> +  int a;
>> +  char b[];
>> +} with_fam_2_v = {.a = 0x1f2f3f4f};
>> +
>> +union with_fam_3 {
>> +  char a[];
>> +  int b[];
>> +} with_fam_3_v = {.b = {0x1f2f3f4f, 0x5f6f7f7f}};
>> +
>> +struct only_fam {
>> +  int b[];
>> +} only_fam_v = {{7, 11}};
>> +
>> +struct only_fam_2 {
>> +  unsigned int : 2;
>> +  unsigned int : 3;
>> +  int b[];
>> +} only_fam_2_v = {{7, 11}};
>> +
>> +int main ()
>> +{
>> +  if (with_fam_1_v.b[3] != 4
>> +      || with_fam_1_v.b[0] != 1)
>> +    __builtin_abort ();
>> +  if (with_fam_2_v.b[3] != 0x1f
>> +      || with_fam_2_v.b[0] != 0x4f)
>> +    __builtin_abort ();
>> +  if (with_fam_3_v.a[0] != 0x4f
>> +      || with_fam_3_v.a[7] != 0x5f)
>> +    __builtin_abort ();
>> +  if (only_fam_v.b[0] != 7
>> +      || only_fam_v.b[1] != 11)
>> +    __builtin_abort ();
>> +  if (only_fam_2_v.b[0] != 7
>> +      || only_fam_2_v.b[1] != 11)
>> +    __builtin_abort ();
>> +
>> +  return 0;
>> +}
>> +
>> diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c
>> new file mode 100644
>> index 000000000000..dd36fa01306d
>> --- /dev/null
>> +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c
>> @@ -0,0 +1,36 @@
>> +/* testing the correct usage of flexible array members in unions
>> +   and alone in structures.  */
>> +/* { dg-do compile } */
>> +/* { dg-options "-pedantic-errors" } */
>> +
>> +union with_fam_1 {
>> +  int a;
>> +  int b[];  /* { dg-error "flexible array member in union is a GCC extension" } */
>> +};
>> +
>> +union with_fam_2 {
>> +  char a;
>> +  int b[];  /* { dg-error "flexible array member in union is a GCC extension" } */
>> +};
>> +
>> +union with_fam_3 {
>> +  char a[];  /* { dg-error "flexible array member in union is a GCC extension" } */
>> +  /* { dg-error "in an otherwise empty" "" { target c++ } .-1 } */
>> +  int b[];  /* { dg-error "flexible array member in union is a GCC extension" } */
>> +};
>> +
>> +struct only_fam {
>> +  int b[];
>> +  /* { dg-error "in a struct with no named members" "" { target c } .-1 } */
>> +  /* { dg-error "in an otherwise empty" "" { target c++ } .-2 } */
>> +  /* { dg-error "forbids flexible array member" "" { target c++ } .-3 } */
>> +};
>> +
>> +struct only_fam_2 {
>> +  unsigned int : 2;
>> +  unsigned int : 3;
>> +  int b[];
>> +  /* { dg-error "in a struct with no named members" "" { target c } .-1 } */
>> +  /* { dg-error "in an otherwise empty" "" { target c++ } .-2 } */
>> +  /* { dg-error "forbids flexible array member" "" { target c++ } .-3 } */
>> +};


      reply	other threads:[~2024-04-25 14:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 14:06 [PATCH v2 0/3] Allow flexible array members in unions and alone in structures [PR53548] Qing Zhao
2024-04-25 14:06 ` [PATCH v2 1/3] " Qing Zhao
2024-04-25 14:06 ` [PATCH v2 2/3] C and C++ FE changes Qing Zhao
2024-04-25 14:06 ` [PATCH v2 3/3] Add testing cases for flexible array members in unions and alone in structures Qing Zhao
2024-04-25 14:13   ` Siddhesh Poyarekar
2024-04-25 14:21     ` Qing Zhao [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C29B1490-4D94-49D4-8D5F-955B7D513B4A@oracle.com \
    --to=qing.zhao@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=josmyers@redhat.com \
    --cc=keescook@chromium.org \
    --cc=richard.guenther@gmail.com \
    --cc=siddhesh@gotplt.org \
    --cc=uecker@tugraz.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).