From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dormouse.elm.relay.mailchannels.net (dormouse.elm.relay.mailchannels.net [23.83.212.50]) by sourceware.org (Postfix) with ESMTPS id 6A9903858C98 for ; Thu, 25 Apr 2024 14:13:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A9903858C98 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A9903858C98 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.212.50 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714054432; cv=pass; b=ArwHvnmd1r7ni/FEURfAdd8AxivM3+bMEA045b72dbX5uRaIjF1VwUq+XByeBeATDUlOQ0Z6THKpNjgo1BogVyq0YwbcRNF6Y+iw4ClquCirQKRlj3p91CwM75+MmhEczhzi7r1TS2azA3YMZV6Yidk+rEp6cDX3MGuIa0A4mPQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714054432; c=relaxed/simple; bh=YuotX805FOuUp4GS6n+gLq2TuL9ozJxDwKVjXfJeRnU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=XgCFxI544bIznCbV6tNw8czZNz8SXuykRLRfWuv+6k4XU9tWZLb6FQ6m3S8Y27pYmkQ83gaDx/ocgnkUsMw/lmtEH3UEJ3wtXGhY5vDkfrL4cUbbe0QiW4N8NOg8DWCW0stH1xsH4eO5yq882PPAz5/fhE0uTGG0T46hrXNty+U= ARC-Authentication-Results: i=2; server2.sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 1716C902615; Thu, 25 Apr 2024 14:13:49 +0000 (UTC) Received: from pdx1-sub0-mail-a312.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 798E5902629; Thu, 25 Apr 2024 14:13:48 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1714054428; a=rsa-sha256; cv=none; b=5fprRqOgsJV1ZXGFHDjNT6LEKSeQf2XlMEyZBNGs1zBjM7IHLe5f1BKaEtxvv/nqgjymCs DoXl/yFCuVR8BdlQADGdbVZplJABu33ou7tIyDyA0toXSCyMUbWqOQCm7KzFw82MAWgSnK HA0fMX682SJXlsN/8YJ1rHdOD2xL1aUueZHCLKPUch8sRhkAnUSSPc6jLgreDT0vtyswti lxAnDYWkuXf4qg7t1aGtxkOb+AZaslx4rxCjRxY8tQTHH0AMMvAcFipnjX5T/W4jrX+nLu ByuBJNSPkjTGE5dze8XPu4DJVP+HOgdSVFqdhJZCQfWGVOVos2PS/tD01Ifiyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1714054428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=704Qef3RWt4tB+n+HoMTRFQsxIG6Mes2KB0iIa5XRuk=; b=GyRfPHWwtkXstxfwCjz/Y2gGxBx1Qww8unb4cyOzNNPuFThI8odq71btaeGI+AV5K9xOWX EjTVScbHXhP689kVwIrxFWDRqOy8vuy0DMKCUzHbaXE01h1yefgOYasjkjnDBATRfzVirY U/htBpwuJZesmDs2Lg5WcrSOlQhaFubWGHHog50Efjky7QoExB0SzXDbVPiIC3pK64w41T 6ye+iqlUiYG/sy021DEwWelxUvGEVu9Ng1yi00McRCeadhtW47drdt1iIRH5ZEldAEnK9w OV0jfRf/Nf0e5HeSwJ5JYNUpXXs8O32wWGxThHIV+0njzbIvAW7vrsQWk0l8Hw== ARC-Authentication-Results: i=1; rspamd-6f55c6f9dc-8pfvr; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Relation-Fumbling: 55e50c306e0eec41_1714054428841_3352777085 X-MC-Loop-Signature: 1714054428841:418450819 X-MC-Ingress-Time: 1714054428841 Received: from pdx1-sub0-mail-a312.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.118.14.240 (trex/6.9.2); Thu, 25 Apr 2024 14:13:48 +0000 Received: from [192.168.0.182] (bras-base-toroon4859w-grc-71-142-198-113-116.dsl.bell.ca [142.198.113.116]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a312.dreamhost.com (Postfix) with ESMTPSA id 4VQHs75q24z81; Thu, 25 Apr 2024 07:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1714054428; bh=704Qef3RWt4tB+n+HoMTRFQsxIG6Mes2KB0iIa5XRuk=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=gkW1eVGZ9gE0HW9zIKU/hPXOaVyrYgBiFu8cViVfAbUuTgLxlarh7RDJwr4Fxvs4/ guRWSuDVllVRNqmnZvmIpRN/iW3q02AfUSAcFVIplWyHvAHodJBb77D9nLSEQI1yTD P/HMHPeE8HWCvUBN2uVKTW3WVySDBwzPsm5/1EdChoF5ptxl4Cl0CiZTXZxvkVwJD5 2kK6O3RxCN9iW9moFqEdHLGnHbkvSmaeQ8oytInYUTS+F3YYD3MkOXR5akbzGFBrMh 0Ptm5GUYjlJ9SaaZawoTj337qtBGGwcgYNu7MAS8v2iZMvl/Uvz9dlIPrrusr+SSX5 JVHaiF5/0XIqA== Message-ID: Date: Thu, 25 Apr 2024 10:13:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/3] Add testing cases for flexible array members in unions and alone in structures. To: Qing Zhao , jason@redhat.com, richard.guenther@gmail.com, josmyers@redhat.com Cc: uecker@tugraz.at, keescook@chromium.org, gcc-patches@gcc.gnu.org References: <20240425140648.1407274-1-qing.zhao@oracle.com> <20240425140648.1407274-4-qing.zhao@oracle.com> Content-Language: en-US From: Siddhesh Poyarekar In-Reply-To: <20240425140648.1407274-4-qing.zhao@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3036.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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? 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 } */ > +};