From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125186 invoked by alias); 6 Jul 2017 15:45:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 125066 invoked by uid 89); 6 Jul 2017 15:45:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS,URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Jul 2017 15:45:18 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1dT8xk-0004pX-Gh from joseph_myers@mentor.com ; Thu, 06 Jul 2017 08:45:04 -0700 Received: from digraph.polyomino.org.uk (137.202.0.87) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Thu, 6 Jul 2017 16:45:00 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.86_2) (envelope-from ) id 1dT8xd-0002Po-8z; Thu, 06 Jul 2017 15:44:57 +0000 Date: Thu, 06 Jul 2017 15:45:00 -0000 From: Joseph Myers To: "H.J. Lu" CC: Martin Sebor , Jason Merrill , GCC Patches Subject: Re: RFC: [PATCH] Add warn_if_not_aligned attribute In-Reply-To: <20170616115455.GA3457@gmail.com> Message-ID: References: <2f2c702d-91e0-edc5-de77-04957b33969e@gmail.com> <6c6c268d-a40b-cfa9-574c-ad235f9205b7@gmail.com> <4a4ac20f-9c27-4844-55dc-38ff56ac138b@gmail.com> <20170616115455.GA3457@gmail.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-SW-Source: 2017-07/txt/msg00333.txt.bz2 On Fri, 16 Jun 2017, H.J. Lu wrote: > +@code{warning: alignment 8 of 'struct foo' is less than 16}. I think @samp is better than @code for warnings, throughout, since they aren't pieces of program code. > +This warning can be disabled by @option{-Wno-if-not-aligned}. > +The @code{warn_if_not_aligned } attribute can also be used for types Stray space before }. > +static void > +handle_warn_if_not_align (tree field, unsigned int record_align) Missing comment above this function explaining its semantics and those of its arguments. > + if ((record_align % warn_if_not_align) != 0) > + warning (opt_w, "alignment %d of %qT is less than %d", > + record_align, context, warn_if_not_align); I'd expect %u for unsigned int alignments, instead of %d. > + unsigned int off > + = (tree_to_uhwi (DECL_FIELD_OFFSET (field)) > + + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field)) / BITS_PER_UNIT); > + if ((off % warn_if_not_align) != 0) > + warning (opt_w, "%q+D offset %d in %qT isn't aligned to %d", > + field, off, context, warn_if_not_align); And you can have struct offsets that don't fit in unsigned int (i.e. structures over 4 GB), so should be using unsigned HOST_WIDE_INT to store the offset and %wu to print it. (Whereas various places in GCC restrict alignments to unsigned int.) What happens if you specify the attribute on a bit-field, or on a type used to declare a bit-field? I don't think either of those particularly makes sense, but I don't see tests for it either. -- Joseph S. Myers joseph@codesourcery.com