From patchwork Thu Jun 16 19:37:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Kabele X-Patchwork-Id: 55143 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 673823848592 for ; Thu, 16 Jun 2022 19:37:51 +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 6BB423857B9D for ; Thu, 16 Jun 2022 19:37:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6BB423857B9D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sysgo.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sysgo.com Date: Thu, 16 Jun 2022 21:37:32 +0200 From: Vit Kabele To: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Extend the -Wpadded message with actual padding size Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, 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" 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. 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 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); + } if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary