public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/50716] Segmentation fault caused by misaligned vector access
Date: Fri, 14 Oct 2011 12:10:00 -0000	[thread overview]
Message-ID: <bug-50716-4-Vb4bCzNKOG@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-50716-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50716

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-14 12:09:27 UTC ---
It's because we do

        align = MAX (TYPE_ALIGN (TREE_TYPE (exp)), get_object_alignment (exp));

which discards the knowledge we have (exp is aligned to 4 bytes,
get_object_alignment returns 4).

Which can be fixed for example by

        align = get_object_alignment_1 (exp, &misalign);
        align = MAX (TYPE_ALIGN (TREE_TYPE (exp)), align);
        if (misalign != 0)
          align = (misalign & -misalign);

so always honor an explicit knowledge about misalignment.  Or less
aggressively,

        align = get_object_alignment_1 (exp, &misalign);
        if (TYPE_ALIGN (TREE_TYPE (exp)) <= align)
          {
            if (misalign != 0)
              align = (misalign & -misalign);
          } 
        else
          align = TYPE_ALIGN (TREE_TYPE (exp));

thus only when the base alignment is at least that of the types alignment.
Which means we'd treat a vector load from a misaligned int * pointer as
aligned, but from a misaligned vector int * pointer not - maybe too surprising,
I'd definitely go with the first variant.  Any idea which reasonable
case we'd miss here?  Even *(vector int *)(int-ptr + 2) would be handled
as aligned, get_object_alignment_1 would return 32 (int aligned), the
misalign is truncated to the base alignment.


  parent reply	other threads:[~2011-10-14 12:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-13 15:00 [Bug middle-end/50716] New: " tema at gcc dot gnu.org
2011-10-13 19:45 ` [Bug middle-end/50716] " pinskia at gcc dot gnu.org
2011-10-13 19:51 ` artyom.shinkaroff at gmail dot com
2011-10-14  9:34 ` rguenth at gcc dot gnu.org
2011-10-14 12:10 ` rguenth at gcc dot gnu.org [this message]
2011-10-14 12:12 ` rguenth at gcc dot gnu.org
2011-10-17 12:22 ` rguenth at gcc dot gnu.org
2011-10-18  8:46 ` rguenth at gcc dot gnu.org
2011-10-18 11:47 ` rguenth at gcc dot gnu.org

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=bug-50716-4-Vb4bCzNKOG@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).