public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joseph Myers <joseph@codesourcery.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: Martin Sebor <msebor@gmail.com>, Jason Merrill <jason@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: RFC: [PATCH] Add warn_if_not_aligned attribute
Date: Thu, 06 Jul 2017 15:45:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.20.1707061537330.7309@digraph.polyomino.org.uk> (raw)
In-Reply-To: <20170616115455.GA3457@gmail.com>

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

  reply	other threads:[~2017-07-06 15:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-04 15:52 H.J. Lu
2017-06-05 15:11 ` Joseph Myers
2017-06-05 17:45   ` H.J. Lu
2017-06-06 16:07     ` Martin Sebor
2017-06-06 16:11       ` Martin Sebor
2017-06-06 16:59         ` H.J. Lu
2017-06-06 17:35           ` Martin Sebor
2017-06-06 22:57             ` H.J. Lu
2017-06-07  0:11               ` Martin Sebor
2017-06-07 13:30                 ` H.J. Lu
2017-06-08 17:00                   ` H.J. Lu
2017-06-08 19:13                     ` Martin Sebor
2017-06-09 13:31                       ` H.J. Lu
2017-06-15 15:38                         ` Martin Sebor
2017-06-15 15:47                           ` H.J. Lu
2017-06-15 17:31                             ` Joseph Myers
2017-06-16 11:55                               ` H.J. Lu
2017-07-06 15:45                                 ` Joseph Myers [this message]
2017-07-08 13:45                                   ` H.J. Lu
2017-08-17 14:19                                     ` Joseph Myers
2017-08-17 16:23                                       ` H.J. Lu
2017-08-18  1:40                                         ` Jason Merrill
2017-08-21 12:02                                         ` Szabolcs Nagy
2017-08-21 12:57                                           ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1707061537330.7309@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=jason@redhat.com \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).