public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "thiago at kde dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/43976]  New: warning about increased alignment during casting printed even though variable is properly aligned
Date: Mon, 03 May 2010 14:40:00 -0000	[thread overview]
Message-ID: <bug-43976-7726@http.gcc.gnu.org/bugzilla/> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2039 bytes --]

Source: https://bugs.webkit.org/show_bug.cgi?id=38045

Given the following code:

$ cat test.cpp
struct Foo
{
    char __attribute__((aligned(4))) c[sizeof(int)];
};

char junk;
Foo f;

int main()
{
    int *i = reinterpret_cast<int *>(&f.c);
    *i = 0;
}

When compiled for ARM produces the warning:
$ arm-none-linux-gnueabi-g++ -Wcast-align -O3 -fsyntax-only /tmp/test.cpp
test.cpp:11: warning: cast from 'char (*)[4]' to 'int*' increases required
alignment of target type

Note that we requested that Foo::c be aligned to 4 bytes, which is the required
alignment for int. The assembly dump of the build confirms that the alignment
was honoured:

junk:
        .space  1
        .space  3
        .type   f, %object
        .size   f, 4
f:
        .space  4

According to Dirk Müller, the following code is at fault (I have no idea where
it's from):
      /* Warn about possible alignment problems.  */
      if (STRICT_ALIGNMENT && warn_cast_align
          && (complain & tf_warning)
·         && !VOID_TYPE_P (type)
·         && TREE_CODE (TREE_TYPE (intype)) != FUNCTION_TYPE
·         && COMPLETE_TYPE_P (TREE_TYPE (type))
·         && COMPLETE_TYPE_P (TREE_TYPE (intype))
·         && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (intype)))
·       warning (OPT_Wcast_align, "cast from %qT to %qT "
                 "increases required alignment of target type", intype, type);

As it only verifies the aligment of the type in question (char*), not of the
variable in question (&f.c).


-- 
           Summary: warning about increased alignment during casting printed
                    even though variable is properly aligned
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: thiago at kde dot org
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-none-linux-gnueabi


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


             reply	other threads:[~2010-05-03 14:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-03 14:40 thiago at kde dot org [this message]
2010-05-04 17:27 ` [Bug middle-end/43976] " pinskia at gcc dot gnu dot org
2010-05-04 19:40 ` thiago at kde dot org
2010-05-05 19:18 ` hp at gcc dot gnu dot org
2010-05-05 19:40 ` thiago at kde dot org
2010-09-08 10:02 ` ibolton at gcc dot gnu dot 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-43976-7726@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).