From patchwork Thu Jun 23 21:21:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Dimitrov X-Patchwork-Id: 55349 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DB7B3850238 for ; Thu, 23 Jun 2022 21:24:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server28.superhosting.bg (server28.superhosting.bg [217.174.156.11]) by sourceware.org (Postfix) with ESMTPS id A1E53384F018 for ; Thu, 23 Jun 2022 21:21:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A1E53384F018 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dinux.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dinux.eu DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dinux.eu; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=RiQWHEHrnQFRpbO9MHGz/ElUX69MW23+aOgpSt0QJI4=; b=kyr4ZozzZZQEwKDgC3SQxptujj OL5g7acq2M/DdI/gVMF1EZicaP2KxE1X3gNNInawF7UaX53mkujtYvghN8xkaV4ZKdoXh0g0B8wRY 6zNY1yJHiQ+cC5RGadEvCqZCFu+6vfl5HlIIA5tw9WwsqK87bkVonHvqNoARQZmfWZWb7zerCRop6 UiIbPHB20sNPjj2mfRlnSTIyU2eemV4wIoepr75FQdiDFpMW1w0xN/G6YEjWtjjUz9AFaLcJNhhcd azgvCIr7pr1N96fJRhDC4v1dqvjtylm30Mn/5hgw+dCQjTnOwLTd9MgQrlos8rfhGvq4NKyAlwGOo Nx4o/MSA==; Received: from [95.87.234.74] (port=58608 helo=kendros.lan) by server28.superhosting.bg with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1o4UGq-0000wH-U8; Fri, 24 Jun 2022 00:21:51 +0300 From: Dimitar Dimitrov To: gcc-patches@gcc.gnu.org Subject: [PATCH] testsuite: Handle default_packed for gcc.dg/builtin-object-size-20.c Date: Fri, 24 Jun 2022 00:21:22 +0300 Message-Id: <20220623212123.149019-5-dimitar@dinux.eu> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server28.superhosting.bg X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - dinux.eu X-Get-Message-Sender-Via: server28.superhosting.bg: authenticated_id: dimitar@dinux.eu X-Authenticated-Sender: server28.superhosting.bg: dimitar@dinux.eu X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The gcc.dg/builtin-object-size-20.c test case assumes that the target inserts padding between structure members. Obviously it fails for targets which pack structures by default. Split the cases into two tests, so that the ones requiring structure padding can be skipped for default_packed targets. Ok for trunk? gcc/testsuite/ChangeLog: * gcc.dg/builtin-object-size-20.c: Remove cases which work on default_packed targets. * gcc.dg/builtin-object-size-22.c: New test with the cases removed above. Signed-off-by: Dimitar Dimitrov --- gcc/testsuite/gcc.dg/builtin-object-size-20.c | 64 +-------------- gcc/testsuite/gcc.dg/builtin-object-size-22.c | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+), 62 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-22.c diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-20.c b/gcc/testsuite/gcc.dg/builtin-object-size-20.c index bed973c2c77..f40e3dcc1a9 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-20.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-20.c @@ -1,7 +1,8 @@ /* PR middle-end/92815 - spurious -Wstringop-overflow writing into a flexible array of an extern struct { dg-do compile } - { dg-options "-O -Wall -fdump-tree-optimized" } */ + { dg-options "-O -Wall -fdump-tree-optimized" } + { dg-skip-if "test assumes that structs have padding" { default_packed } } */ #define ASSERT(expr) ((expr) ? (void)0 : fail (__LINE__)) #define bos0(expr) __builtin_object_size (expr, 1) @@ -18,44 +19,6 @@ typedef __SIZE_TYPE__ size_t; extern void fail (int); -/* Verify sizes of a struct with a flexible array member and no padding. */ - -struct ACX { char n, a[]; }; - -struct ACX ac0 = { }; -struct ACX ac1 = { 1, { 1 } }; -struct ACX ac2 = { 2, { 1, 2 } }; -struct ACX ac3 = { 3, { 1, 2, 3 } }; - -extern struct ACX eacx; - -void facx (void) -{ - ASSERT (bos0 (&ac0) == sizeof ac0); - ASSERT (bos0 (&ac1) == 2); - ASSERT (bos0 (&ac2) == 3); - ASSERT (bos0 (&ac3) == 4); - ASSERT (bos0 (&eacx) == (size_t)-1); - - ASSERT (bos1 (&ac0) == sizeof ac0); - ASSERT (bos1 (&ac1) == 2); - ASSERT (bos1 (&ac2) == 3); - ASSERT (bos1 (&ac3) == 4); - ASSERT (bos1 (&eacx) == (size_t)-1); - - ASSERT (bos2 (&ac0) == sizeof ac0); - ASSERT (bos2 (&ac1) == 2); - ASSERT (bos2 (&ac2) == 3); - ASSERT (bos2 (&ac3) == 4); - ASSERT (bos2 (&eacx) == sizeof eacx); - - ASSERT (bos3 (&ac0) == sizeof ac0); - ASSERT (bos3 (&ac1) == 2); - ASSERT (bos3 (&ac2) == 3); - ASSERT (bos3 (&ac3) == 4); - ASSERT (bos3 (&eacx) == sizeof eacx); -} - /* Verify sizes of a struct with a flexible array member and 1 byte @@ -289,27 +252,4 @@ void fai64cx (void) ASSERT (bos3 (&eai64cx) == sizeof eai64cx); } - -/* Also verify sizes of a struct with a zero length array member. */ - -struct A0C0 { char n, a[0]; }; - -struct A0C0 a0c0 = { }; -extern struct A0C0 ea0c0; - -void fa0c0 (void) -{ - ASSERT (bos0 (&a0c0) == sizeof a0c0); - ASSERT (bos0 (&ea0c0) == sizeof ea0c0); - - ASSERT (bos1 (&a0c0) == sizeof a0c0); - ASSERT (bos1 (&a0c0) == sizeof ea0c0); - - ASSERT (bos2 (&a0c0) == sizeof a0c0); - ASSERT (bos2 (&a0c0) == sizeof ea0c0); - - ASSERT (bos3 (&a0c0) == sizeof a0c0); - ASSERT (bos3 (&a0c0) == sizeof ea0c0); -} - /* { dg-final { scan-tree-dump-not "fail" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-22.c b/gcc/testsuite/gcc.dg/builtin-object-size-22.c new file mode 100644 index 00000000000..1e55229c949 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-object-size-22.c @@ -0,0 +1,79 @@ +/* PR middle-end/92815 - a variant of gcc.dg/builtin-object-size-20.c + prepared for all targets, irregardless if they pack or not + the structs by default. + { dg-do compile } + { dg-options "-O -Wall -fdump-tree-optimized" } */ + +#define ASSERT(expr) ((expr) ? (void)0 : fail (__LINE__)) +#define bos0(expr) __builtin_object_size (expr, 1) +#define bos1(expr) __builtin_object_size (expr, 1) +#define bos2(expr) __builtin_object_size (expr, 2) +#define bos3(expr) __builtin_object_size (expr, 3) + +typedef __SIZE_TYPE__ size_t; + + +extern void fail (int); + + +/* Verify sizes of a struct with a flexible array member and no padding. */ + +struct ACX { char n, a[]; }; + +struct ACX ac0 = { }; +struct ACX ac1 = { 1, { 1 } }; +struct ACX ac2 = { 2, { 1, 2 } }; +struct ACX ac3 = { 3, { 1, 2, 3 } }; + +extern struct ACX eacx; + +void facx (void) +{ + ASSERT (bos0 (&ac0) == sizeof ac0); + ASSERT (bos0 (&ac1) == 2); + ASSERT (bos0 (&ac2) == 3); + ASSERT (bos0 (&ac3) == 4); + ASSERT (bos0 (&eacx) == (size_t)-1); + + ASSERT (bos1 (&ac0) == sizeof ac0); + ASSERT (bos1 (&ac1) == 2); + ASSERT (bos1 (&ac2) == 3); + ASSERT (bos1 (&ac3) == 4); + ASSERT (bos1 (&eacx) == (size_t)-1); + + ASSERT (bos2 (&ac0) == sizeof ac0); + ASSERT (bos2 (&ac1) == 2); + ASSERT (bos2 (&ac2) == 3); + ASSERT (bos2 (&ac3) == 4); + ASSERT (bos2 (&eacx) == sizeof eacx); + + ASSERT (bos3 (&ac0) == sizeof ac0); + ASSERT (bos3 (&ac1) == 2); + ASSERT (bos3 (&ac2) == 3); + ASSERT (bos3 (&ac3) == 4); + ASSERT (bos3 (&eacx) == sizeof eacx); +} + +/* Also verify sizes of a struct with a zero length array member. */ + +struct A0C0 { char n, a[0]; }; + +struct A0C0 a0c0 = { }; +extern struct A0C0 ea0c0; + +void fa0c0 (void) +{ + ASSERT (bos0 (&a0c0) == sizeof a0c0); + ASSERT (bos0 (&ea0c0) == sizeof ea0c0); + + ASSERT (bos1 (&a0c0) == sizeof a0c0); + ASSERT (bos1 (&a0c0) == sizeof ea0c0); + + ASSERT (bos2 (&a0c0) == sizeof a0c0); + ASSERT (bos2 (&a0c0) == sizeof ea0c0); + + ASSERT (bos3 (&a0c0) == sizeof a0c0); + ASSERT (bos3 (&a0c0) == sizeof ea0c0); +} + +/* { dg-final { scan-tree-dump-not "fail" "optimized" } } */