From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16107 invoked by alias); 3 May 2010 14:40:27 -0000 Received: (qmail 16073 invoked by uid 48); 3 May 2010 14:40:15 -0000 Date: Mon, 03 May 2010 14:40:00 -0000 Subject: [Bug c++/43976] New: warning about increased alignment during casting printed even though variable is properly aligned X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "thiago at kde dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-05/txt/msg00196.txt.bz2 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(&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