public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
@ 2013-10-17 23:33 roothorick at gmail dot com
  2013-10-18  8:30 ` [Bug c++/58772] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: roothorick at gmail dot com @ 2013-10-17 23:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58772
           Summary: __attribute__((aligned(16))) and nested classes cause
                    -ftree-vectorize to generate segfaulting code
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roothorick at gmail dot com

Created attachment 31027
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31027&action=edit
Testcase for the bug

Compile the attached code with:

g++ -m32 -O1 -msse2 -ftree-vectorize

It will segfault when run.

Any of the following will remove the segfault:

* Removing -m32 (that is, compiling for x86-64)
* Removing -msse2 (presumably because -ftree-vectorize no longer has an
instruction to vectorize with)
* Removing -ftree-vectorize (presumably the source of the bug)
* Changing __attribute__((aligned(16))) to 32, or removing it entirely.

I do not know if the testcase is in the most reduced form; I just kept adding
things until it did what I saw happening in my (much larger, ~300kLOC)
codebase.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
@ 2013-10-18  8:30 ` rguenth at gcc dot gnu.org
  2013-10-18 15:41 ` roothorick at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-18  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-10-18
                 CC|                            |paolo.carlini at oracle dot com
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  The vectorizer thinks that 'subs' is 16-byte aligned and uses
movaps for the vectorized store.  Actor is layed out correctly (alignment
16 and Sub at a 16 byte alignment boundary), but 'new' returns an 8-byte
aligned pointer.  ISTR it is a known issue that using 'new' with custom
aligned classes doesn't work reliably - the same is true for C code where
using malloc to allocate the class would be wrong, you'd have to use
posix_memalign or a similar function.

Thus, this is an invalid report (but I suppose we should be easily able
to warn in case new is applied to a type with user-specified alignment?).

Keeping as diagnostic enhancement.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
  2013-10-18  8:30 ` [Bug c++/58772] " rguenth at gcc dot gnu.org
@ 2013-10-18 15:41 ` roothorick at gmail dot com
  2013-10-21  8:52 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: roothorick at gmail dot com @ 2013-10-18 15:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Ben "root" Anderson <roothorick at gmail dot com> ---
So what this code should be doing, then, is to hint new with 16-byte alignment?
What would the syntax for that be?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
  2013-10-18  8:30 ` [Bug c++/58772] " rguenth at gcc dot gnu.org
  2013-10-18 15:41 ` roothorick at gmail dot com
@ 2013-10-21  8:52 ` rguenth at gcc dot gnu.org
  2013-10-21  9:04 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-21  8:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
The syntax would be

int main()
{
  Actor *act;
  ::posix_memalign (&act, 16, sizeof (Actor));
  new (*act) Actor;
}

that is, you have to use a different allocator.  Paolo, does libstdc++
provide a custom allocator for aligned memory?  Is this issue going to
be resolved with C++1y?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
                   ` (2 preceding siblings ...)
  2013-10-21  8:52 ` rguenth at gcc dot gnu.org
@ 2013-10-21  9:04 ` paolo.carlini at oracle dot com
  2013-10-21  9:35 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-21  9:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This is relevant
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3396.htm but it's late
for C++14, hopefully for C++17. Honestly I didn't follow the topic much last
year, I'll try to further investigate.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
                   ` (3 preceding siblings ...)
  2013-10-21  9:04 ` paolo.carlini at oracle dot com
@ 2013-10-21  9:35 ` burnus at gcc dot gnu.org
  2013-10-21  9:50   ` pinskia
  2013-10-21 10:07 ` burnus at gcc dot gnu.org
  2013-10-22  9:50 ` paolo.carlini at oracle dot com
  6 siblings, 1 reply; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-10-21  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

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

--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #3)
> The syntax would be
>   ::posix_memalign (&act, 16, sizeof (Actor));

Or
  #include <mm_malloc.h>
  ...
  act = _mm_malloc, sizeof (Actor), 16);
which is supposed to be a bit more portable. (mm_malloc.h ships with GCC since
4.0, if I recall correctly.)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-21  9:35 ` burnus at gcc dot gnu.org
@ 2013-10-21  9:50   ` pinskia
  0 siblings, 0 replies; 9+ messages in thread
From: pinskia @ 2013-10-21  9:50 UTC (permalink / raw)
  To: burnus at gcc dot gnu.org; +Cc: gcc-bugs



Sent from my iPad

> On Oct 21, 2013, at 2:35 AM, "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> wrote:
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58772
> 
> Tobias Burnus <burnus at gcc dot gnu.org> changed:
> 
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                 CC|                            |burnus at gcc dot gnu.org
> 
> --- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
> (In reply to Richard Biener from comment #3)
>> The syntax would be
>>  ::posix_memalign (&act, 16, sizeof (Actor));
> 
> Or
>  #include <mm_malloc.h>
>  ...
>  act = _mm_malloc, sizeof (Actor), 16);
> which is supposed to be a bit more portable. (mm_malloc.h ships with GCC since
> 4.0, if I recall correctly.)


Less portable as that only works on x86 while posix_memalign works on all posix targets.
>From gcc-bugs-return-432334-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Oct 21 09:50:11 2013
Return-Path: <gcc-bugs-return-432334-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 24526 invoked by alias); 21 Oct 2013 09:50:10 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 24231 invoked by uid 55); 21 Oct 2013 09:50:07 -0000
From: "pinskia at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
Date: Mon, 21 Oct 2013 09:50:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.8.1
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: pinskia at gmail dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-58772-4-biqSkdOvdG@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58772-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58772-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-10/txt/msg01478.txt.bz2
Content-length: 1041

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX772

--- Comment #6 from pinskia at gmail dot com <pinskia at gmail dot com> ---
Sent from my iPad

> On Oct 21, 2013, at 2:35 AM, "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> wrote:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?idX772
>
> Tobias Burnus <burnus at gcc dot gnu.org> changed:
>
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                 CC|                            |burnus at gcc dot gnu.org
>
> --- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> ---
> (In reply to Richard Biener from comment #3)
>> The syntax would be
>>  ::posix_memalign (&act, 16, sizeof (Actor));
>
> Or
>  #include <mm_malloc.h>
>  ...
>  act = _mm_malloc, sizeof (Actor), 16);
> which is supposed to be a bit more portable. (mm_malloc.h ships with GCC since
> 4.0, if I recall correctly.)


Less portable as that only works on x86 while posix_memalign works on all posix
targets.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
                   ` (4 preceding siblings ...)
  2013-10-21  9:35 ` burnus at gcc dot gnu.org
@ 2013-10-21 10:07 ` burnus at gcc dot gnu.org
  2013-10-22  9:50 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-10-21 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to pinskia@gmail.com from comment #6)
> Less portable as that only works on x86 while posix_memalign works on all
> posix targets.

Or more portable as it also works on non-POSIX platforms such as (non-ARM)
Windows. (Then aligning manually.) See PR16570. Thus, one can choose whether
one wants to be more compatible with non-POSIX x86-64/i386 systems or with
non-x86-64/i386 POSIX systems.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/58772] __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code
  2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
                   ` (5 preceding siblings ...)
  2013-10-21 10:07 ` burnus at gcc dot gnu.org
@ 2013-10-22  9:50 ` paolo.carlini at oracle dot com
  6 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-22  9:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Personally, I would not object to experimentation like that in PR55727, but it
should happen in a separate allocator, not new_allocator. Still, I'm under the
impression that N3396 is superseding a lot of library-only strategies, now it's
late for those...


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-10-22  9:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-17 23:33 [Bug c++/58772] New: __attribute__((aligned(16))) and nested classes cause -ftree-vectorize to generate segfaulting code roothorick at gmail dot com
2013-10-18  8:30 ` [Bug c++/58772] " rguenth at gcc dot gnu.org
2013-10-18 15:41 ` roothorick at gmail dot com
2013-10-21  8:52 ` rguenth at gcc dot gnu.org
2013-10-21  9:04 ` paolo.carlini at oracle dot com
2013-10-21  9:35 ` burnus at gcc dot gnu.org
2013-10-21  9:50   ` pinskia
2013-10-21 10:07 ` burnus at gcc dot gnu.org
2013-10-22  9:50 ` paolo.carlini at oracle dot com

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).