From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by sourceware.org (Postfix) with ESMTPS id 1F2AC3856DCD for ; Fri, 17 Jun 2022 12:57:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F2AC3856DCD Received: by mail-vs1-xe2f.google.com with SMTP id j39so3989720vsv.11 for ; Fri, 17 Jun 2022 05:57:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kDQNhRElSwrg0tiYKJFRSbjjKajrqhdhmnZJXHQUSeY=; b=yxfAUCjDGfwCyFo0Hc3UnxqWl0qRFGGMjK/qYOQ/DN9YzNyxgJUpA2NTSAL3jcyjuW vE8PvzZuHcnUtOBXJajNPras1ykYjN91crhur8NbU6DeT31TzEHZwBeN4hhZh3lq2VQ/ /eOWLkVl8fz1nh7rviEYqvruCQICEgqfFyWz00YpwUEEvNJp1PHK+oSB3qmFo/ZUsAQl yh3Y8ahs2KY+ahMGKeVLxEneWa21ETPVEXy7BphlstLBJtK4EXmKLRWny1KZlEB9hzVS ZvTTM6egOAaUnNK6wWok6q60RxGWDUXp570NVx4sGXMHXB+f4eKBkKbkvoe3BYd5xewQ jDjQ== X-Gm-Message-State: AJIora8YGUt94bttfvQkvZ0ybMXNsrbWV1iDr087PAUb+9wB32LPA95C QPRga3rLdbMNv143/jbI0rGOLE58nQ1MHQkmGs3WST+gs70= X-Google-Smtp-Source: AGRyM1tOHBB5O0N7EA7kIbeqylFMIhPts4BSd6M5tfwV4NQOi5PIXVgmDZtYTQaWq055Z3omVLpxIMSqdlhYskfcVOI= X-Received: by 2002:a67:f70e:0:b0:34b:915c:15f5 with SMTP id m14-20020a67f70e000000b0034b915c15f5mr4224320vso.44.1655470620484; Fri, 17 Jun 2022 05:57:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Eric Gallager Date: Fri, 17 Jun 2022 08:56:49 -0400 Message-ID: Subject: Re: [PATCH] c: Extend the -Wpadded message with actual padding size To: Vit Kabele Cc: gcc-patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-List-Received-Date: Fri, 17 Jun 2022 12:57:05 -0000 On Thu, Jun 16, 2022 at 3:37 PM Vit Kabele wrote: > > When the compiler warns about padding struct to alignment boundary, it > now also informs the user about the size of the alignment that needs to > be added to get rid of the warning. Hi, thanks for taking the time to improve -Wpadded; I have been wishing that GCC's implementation of -Wpadded would print this information for a while now and thought there was a bug open for it, but can't seem to find it now... > > This removes the need of using pahole or similar tools, or manually > determining the padding size. > > Tested on x86_64-pc-linux-gnu. > > gcc/ChangeLog: > > * stor-layout.cc (finalize_record_size): Improve warning message > > Signed-off-by: Vit Kabele > --- > gcc/stor-layout.cc | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc > index 765f22f68b9..57ddb001780 100644 > --- a/gcc/stor-layout.cc > +++ b/gcc/stor-layout.cc > @@ -1781,7 +1781,14 @@ finalize_record_size (record_layout_info rli) > && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0 > && input_location != BUILTINS_LOCATION > && !TYPE_ARTIFICIAL (rli->t)) > - warning (OPT_Wpadded, "padding struct size to alignment boundary"); > + { > + tree padding_size > + = size_binop (MINUS_EXPR, > + TYPE_SIZE_UNIT (rli->t), unpadded_size_unit); > + warning (OPT_Wpadded, > + "padding struct size to alignment boundary with %E bytes", > + padding_size); > + } Style nit: indentation seems off; check your tabs vs. spaces etc. > > if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE > && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary > -- > 2.30.2