From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 16E3F3856DF4 for ; Fri, 17 Jun 2022 14:06:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16E3F3856DF4 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-539-4vqVeP8CPoqFMNqtknSzFA-1; Fri, 17 Jun 2022 10:06:30 -0400 X-MC-Unique: 4vqVeP8CPoqFMNqtknSzFA-1 Received: by mail-qk1-f200.google.com with SMTP id az18-20020a05620a171200b006a708307e94so5068632qkb.14 for ; Fri, 17 Jun 2022 07:06:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=4oPvseEPniLYswwSaFrteI68enFCkhQeLrnZHn5pm6o=; b=LG75OKMgdJF43mYtxw1WeQuIqeFmwPW1AIQPdcCAWlPfFICvw4H+u2Gfznvw0fnUPP kNyL7YXeq2X9FFGj88m+qRfCGvRR73qepW09Tobp/CP+OLaLsIz/z/gOepiw1K5OjHSH eD8nB+z+6a7+NtRII6smSMSfaa/731Hqf2Ei8cPLIPVP0XED87LBXaeCmxzIOD85zEyE 6Hv0zDefgJFH9RJTjTyO/nBntGpWw0xtHak8Y3RT3KZkRjMr7Xv5GPVmE3kLSCNNgIkG uVZyCsJsXcFq4WmlLpomENA7QYPi59DUGh4byBr2dasRACUfCGkkod0O39Yt7iOTtJyY vCTQ== X-Gm-Message-State: AJIora94OaXPmL4cyCQrPDrVuzQZcQwfY0ISJu3j+hWt0JiMWOZRDKM+ Fc//KlbGVuX4Sk4a9/LAuX9bk9XZ5NhU1dy/48agAGkPBwmZL7yFqEuZUK0YTbk3Xt1nLe70964 v8bRZUgqVnoEEXlFZyA== X-Received: by 2002:a05:6214:f06:b0:46b:56ce:f94c with SMTP id gw6-20020a0562140f0600b0046b56cef94cmr8501767qvb.103.1655474789634; Fri, 17 Jun 2022 07:06:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u9/XnJMQfXUU7lYuhIt3J+Dg7gnYccbOiWO7xq3jZA0l8/CsTFKGwHXbk31g4xWxXYqbvyVg== X-Received: by 2002:a05:6214:f06:b0:46b:56ce:f94c with SMTP id gw6-20020a0562140f0600b0046b56cef94cmr8501734qvb.103.1655474789302; Fri, 17 Jun 2022 07:06:29 -0700 (PDT) Received: from redhat.com ([2601:184:4780:4310::9979]) by smtp.gmail.com with ESMTPSA id d17-20020a05620a141100b006a6c230f5e0sm3951546qkj.31.2022.06.17.07.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 07:06:28 -0700 (PDT) Date: Fri, 17 Jun 2022 10:06:26 -0400 From: Marek Polacek To: Vit Kabele Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c: Extend the -Wpadded message with actual padding size Message-ID: References: MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.5 (2022-05-16) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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 14:06:35 -0000 On Thu, Jun 16, 2022 at 09:37:32PM +0200, 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. > > This removes the need of using pahole or similar tools, or manually > determining the padding size. Thanks for the patch, it looks reasonable, with the formatting fixed. It would be nice to have a testcase, at least something like struct S { __UINT64_TYPE__ i; char c; }; The problem is what value to check for, on 32-bit arches the padding is probably 3 bytes large and on 64-bit arches probably 7 bytes. So I think you could use __attribute__((aligned (8))) and then it's always 7. > Tested on x86_64-pc-linux-gnu. > > gcc/ChangeLog: > > * stor-layout.cc (finalize_record_size): Improve warning message Missing '.' at the end. > > 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 > -- > 2.30.2 > Marek