From patchwork Tue Feb 7 12:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vit Kabele X-Patchwork-Id: 53866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2826066wrn; Tue, 7 Feb 2023 04:43:28 -0800 (PST) X-Google-Smtp-Source: AK7set8omafAgc0zDhuotPK/oJJA75EI6purlyto284WW+6UXjy3Pgx7QsidHflO/6sRCjqwkadg X-Received: by 2002:a17:907:720b:b0:8a5:8620:575 with SMTP id dr11-20020a170907720b00b008a586200575mr4337133ejc.3.1675773808548; Tue, 07 Feb 2023 04:43:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675773808; cv=none; d=google.com; s=arc-20160816; b=Jh2LyPGLYUZfIS6r5c9EU8mCCpV4od/MN8xm04Lf5+Ou+9TU+sFCMdybP4ZEOjzz44 UIql/5xUxK19wN5/jL9Ac0IuQDlWG0Ab9azixCqllR6YKrrfxZz3fg7CWbTt+cTFVCz9 gRq4mR+0R6QP8+z0NDon1V634B0hP3ENnRmpo2lMCwny3eSdvXNrbKXsSpyVdVVr96f1 KM8bCrKg8mW5nnE3eJNFmOOTC7fwGlewk6fuhh9nEqT1qsVeQecisiOpmQqcC+eQW7de 2j+CicSfTRjP92C1ct8qf7/Jgo8KLf5xz+QxuA7ejj9MALZDbMu1B/UhUJKd6H4OZYG8 vLPA== 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:message-id:date:subject:cc:to:from:dmarc-filter :delivered-to; bh=9VTe7flszhe0evIIT6T1iCMmKdUurIawapzjMvgpHJs=; b=bk/y8yjtulnpSniKWbVSl47/YwzpEuh+To+hnDrn8JWUXtqdwW19ZpTTBuP2Zayzk7 yUQIND40HPGxdiFNiYLw7tv4LxM6bU2hmeeKlXEV6gOzo3CWjT/JlQlFRZbW0MqxOTxq Q/6KvYULboJvc2xtLGo6vkZgirag8oo7TGke3xo6wIjEwsbojqKtpH3Rd4m3g0QzOMn9 TqGiNfAlsX+2wPOmS9lRanZQTl47pir+j5dPX945zm38BpwT+3KwEL4Yxei01VHCv1WA m0paTqEHFdZOnxgTbAai+siX+EztRDMQSDgveKk33VmiXcswhY3A2wDTBnWSmYgBp0ER +Zeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id zz14-20020a170907350e00b00870ecd1a337si15393081ejb.460.2023.02.07.04.43.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 04:43:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 9CCF3385B51C for ; Tue, 7 Feb 2023 12:43:09 +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 1DEBB3858D33 for ; Tue, 7 Feb 2023 12:42:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1DEBB3858D33 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]:52130) by mail.sysgo.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pPNJ4-0001oz-2d; Tue, 07 Feb 2023 13:42:42 +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] Print padding size when aligning struct member Date: Tue, 7 Feb 2023 13:41:57 +0100 Message-Id: <20230207124156.853506-1-vit.kabele@sysgo.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 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?1757176196745028299?= 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..fb1948b94af 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..35ff013026f 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 3 bytes to align 'i'" } */ diff --git a/gcc/testsuite/gcc.dg/Wpadded.c b/gcc/testsuite/gcc.dg/Wpadded.c index 70fcd79a6d4..357e7f61e4a 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 7 bytes to align" "" { target { ! default_packed } } } */ } futz;