From patchwork Fri Feb 24 07:28:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vit Kabele X-Patchwork-Id: 61165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp756747wrd; Thu, 23 Feb 2023 23:30:40 -0800 (PST) X-Google-Smtp-Source: AK7set9RQCUrD74QckXSLsj+uefd8yBogChn/CpD5MhrIvAlm6XtGVSL81kh2/7sUMB/Oz0tg4JD X-Received: by 2002:aa7:c643:0:b0:4ac:c39b:8450 with SMTP id z3-20020aa7c643000000b004acc39b8450mr12913592edr.8.1677223839958; Thu, 23 Feb 2023 23:30:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677223839; cv=none; d=google.com; s=arc-20160816; b=FGb5tSQ/jGjz1lkh/G7j+URGxY8HRLpqDAeGwHX53wp16UOEUCbYxvnII0Usb4QkOT qGfjyq/ReXqBP8IUQ6vM4tMCmSVVx/rddYG8kWgW07xnvXuV8NQK6AMmZgbr3daESaJz 0rELOhtgB4HEAAPO/10hMs1KeEgrt2VPo5LsxAHAGNwvkwUnhwAaUwFl8xfV8G/mtj07 x24XlJNTQKGxzD/LJAFsent59jTN6iCSAJjyEFTUqCW/d9tZ5uJCOUNjdANtnCvni37o yq55vJnfPF7MmogQRTinq5En/+jQ66Mah+nJAj4pzLYk27Mh2/LPFzMpC77/cBduclIZ zJgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to; bh=aXNKeX1mi8l+GbXH6gWWTozIf7QQF2gSJrtlViddv4Q=; b=bkJUE4KQTgyFONu3KIkoT0VJM4tnsolMGUZzqJAXDHqcRAyAS+/wHFVBPZrNSVqrdl ludG/hONcO8gvMyoTyHiTaDBI4hbnJNLkqogeHvvskyMHU3x1if09qtvyMBq4isaMgyT JDToO0Bi8Q/PKatGXmefW+kUpHsgCBqi5omXVQI0ylrVdTt3bB1a0m03dO1ui5k6VyUT p7Q8Dk4Y6/E7OelSaRGyR8vfgSD5KmBgwYoyheKHK/X5+KVn+iTomfyioaspcDSBMwJu gm+aTEPC8rrvKbtYWhEVrDKGonM7Ufp6hG/5EizguPLKXFho5qJVkA4OD5m9SSB771w4 X++A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i5-20020a50fc05000000b004acc030698dsi9405659edr.513.2023.02.23.23.30.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 23:30:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FA5B385B50C for ; Fri, 24 Feb 2023 07:30:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.sysgo.com (mail.sysgo.com [159.69.174.51]) by sourceware.org (Postfix) with ESMTPS id C2B65385840F for ; Fri, 24 Feb 2023 07:30:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2B65385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sysgo.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sysgo.com Received: from lantia.sysgo.com ([172.20.1.5]:35932) by mail.sysgo.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pVSWp-0007Ie-1X; Fri, 24 Feb 2023 08:30:03 +0100 From: =?utf-8?q?V=C3=ADt_Kabele?= To: gcc-patches@gcc.gnu.org Cc: vit@kabele.me, =?utf-8?q?V=C3=ADt_Kabele?= Subject: [PATCH v2] Print padding size when aligning struct member Date: Fri, 24 Feb 2023 08:28:36 +0100 Message-Id: <20230224072835.12177-1-vit.kabele@sysgo.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757176196745028299?= X-GMAIL-MSGID: =?utf-8?q?1758696665103990509?= Hello, I changed the tested pattern to match even on targets with different alignment. BR, VK -- >8 -- Announce the size of introduced padding when compiling with -Wpadded. gcc/ChangeLog: * stor-layout.cc (place_field): Change warning message format gcc/testsuite/ChangeLog: * c-c++-common/Wpadded.c: Add new testcase * gcc.dg/Wpadded.c: Update the expected warning message Signed-off-by: Vít Kabele --- gcc/stor-layout.cc | 2 +- gcc/testsuite/c-c++-common/Wpadded.c | 1 + gcc/testsuite/gcc.dg/Wpadded.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc index 45bf2d18639..1d2bd61eeae 100644 --- a/gcc/stor-layout.cc +++ b/gcc/stor-layout.cc @@ -1346,7 +1346,7 @@ place_field (record_layout_info rli, tree field) if (!targetm.ms_bitfield_layout_p (rli->t) && DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION && !TYPE_ARTIFICIAL (rli->t)) - warning (OPT_Wpadded, "padding struct to align %q+D", field); + warning (OPT_Wpadded, "padding struct with %d bytes to align %q+D", (desired_align - known_align)/8, field); /* If the alignment is still within offset_align, just align the bit position. */ diff --git a/gcc/testsuite/c-c++-common/Wpadded.c b/gcc/testsuite/c-c++-common/Wpadded.c index c5be4686822..0818ea03690 100644 --- a/gcc/testsuite/c-c++-common/Wpadded.c +++ b/gcc/testsuite/c-c++-common/Wpadded.c @@ -11,4 +11,5 @@ * 4 byte fields to 2 byte boundary. */ struct S { __UINT32_TYPE__ i; char c; } __attribute__((aligned(4))); /* { dg-warning "padding struct size to alignment boundary with 3 bytes" } */ +struct R { char c; __UINT32_TYPE__ i; } __attribute__((aligned(4))); /* { dg-warning "padding struct with" } */ diff --git a/gcc/testsuite/gcc.dg/Wpadded.c b/gcc/testsuite/gcc.dg/Wpadded.c index 70fcd79a6d4..218b37d1abc 100644 --- a/gcc/testsuite/gcc.dg/Wpadded.c +++ b/gcc/testsuite/gcc.dg/Wpadded.c @@ -10,5 +10,5 @@ struct foo { char bar; - long baz; /* { dg-warning "padding struct to align" "" { target { ! default_packed } } } */ + long baz; /* { dg-warning "padding struct with" "" { target { ! default_packed } } } */ } futz;