public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63157] New: may_alias doesn't work as expected in template nested types
@ 2014-09-03 18:47 haynberg at sig dot com
  2014-09-04 15:43 ` [Bug c++/63157] " haynberg at sig dot com
  2014-09-05  8:48 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: haynberg at sig dot com @ 2014-09-03 18:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63157

            Bug ID: 63157
           Summary: may_alias doesn't work as expected in template nested
                    types
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: haynberg at sig dot com

Basically, I want to build with strict aliasing enabled however I'd like a way
to *programmatically* prevent strict aliasing optimizations if needed.  I
believe may_alias is the only way one can do this (please let me know if there
are others).  

Here's an example where I know two different-typed pointers may alias.  I
wanted a helper class that I could a reuse.  Note: this is only for structs
which are POD (as you can't inherit from built-in types; I have another utility
for that).

In the example, may_alias works in the non-template case (case 2) and in the
template case if you use a reference (case 4); but not if you use a pointer
(case 3).  Do you know why?

$ cat t.cpp
extern "C" void abort();

struct msg {
   long seq_no;
};

struct msg_alias : msg {} __attribute__((may_alias));

template <typename T>
struct test_type {
   struct type : T {} __attribute__((may_alias));
};

void check(short *a, msg *b)
{
   *a = 5;

   // case 1: will abort
   // b->seq_no = 6;

   // case 2: will not abort; may_alias prevented strict aliasing optimizations
   // msg_alias *p = (msg_alias*) b;
   // p->seq_no = 6;

   // case 3: will abort (but should be the same as case 2)
   test_type<msg>::type *p = (test_type<msg>::type*) b;
   p->seq_no = 6;

   // case 4: will not abort; may_alias prevented strict aliasing optimizations
   // test_type<msg>::type &r = * (test_type<msg>::type*) b;
   // r.seq_no = 6;

   if (*a == 5)
     abort();
}

int main()
{
   msg m[1];
   check((short *) m, m);
}
$ g++ -O3 t.cpp && a.out
Aborted
$ g++ -v
gcc version 4.9.0 (GCC)
$ uname -irs
Linux 3.0.38-0.5-default x86_64


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

* [Bug c++/63157] may_alias doesn't work as expected in template nested types
  2014-09-03 18:47 [Bug c++/63157] New: may_alias doesn't work as expected in template nested types haynberg at sig dot com
@ 2014-09-04 15:43 ` haynberg at sig dot com
  2014-09-05  8:48 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: haynberg at sig dot com @ 2014-09-04 15:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63157

--- Comment #2 from haynberg at sig dot com ---
I recently read your old PR about placement new -
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29286.

Is using placement new also a means to prevent strict-aliasing optimizations
here?  I don’t think so.  Since the following also aborts.

$ cat t.cpp
#include <memory>
#include <stdlib.h>

struct msg {
   long seq_no;
};

void check(char *p)
{
   short *a = new (p) short;
   *a = 5;

   msg *b = new (p) msg;
   b->seq_no = 6;

   a = new (p) short;
   if (*a == 5)
     abort();
}

int main()
{
   msg m[1];
   check((char*) m);
}
$ g++ -O3 -fno-strict-aliasing t.cpp && a.out
$ g++ -O3 t.cpp && a.out
Aborted
>From gcc-bugs-return-461227-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Sep 04 15:44:15 2014
Return-Path: <gcc-bugs-return-461227-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 16059 invoked by alias); 4 Sep 2014 15:44:15 -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 16010 invoked by uid 48); 4 Sep 2014 15:44:12 -0000
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug go/63170] gccgo testcase recover.go fails execution with message 'missing recover' on ppc64 and ppc64le
Date: Thu, 04 Sep 2014 15:44:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: go
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ubizjak at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: ian at airs dot com
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-63170-4-Hz8TGJ3C59@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63170-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63170-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-09/txt/msg01061.txt.bz2
Content-length: 147

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63170

--- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
Probably dup of PR60406.
>From gcc-bugs-return-461228-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Sep 04 15:51:30 2014
Return-Path: <gcc-bugs-return-461228-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 21354 invoked by alias); 4 Sep 2014 15:51:29 -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 21323 invoked by uid 48); 4 Sep 2014 15:51:25 -0000
From: "carrot at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/63156] web can't handle AUTOINC correctly
Date: Thu, 04 Sep 2014 15:51:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: rtl-optimization
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: carrot at google dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: steven at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-63156-4-9mhvBmiGj4@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63156-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63156-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: 2014-09/txt/msg01062.txt.bz2
Content-length: 568

https://gcc.gnu.org/bugzilla/show_bug.cgi?idc156

--- Comment #6 from Carrot <carrot at google dot com> ---
(In reply to Steven Bosscher from comment #5)
> (In reply to Carrot from comment #4)
> > For a AUTOINC rtl expression, we create two refs, one def and one use, but
> > only the def gets the flag DF_REF_READ_WRITE, the use doesn't have this flag.
>
> Then this is fall-out of PR32339.

Since it is intentionally to remove flag DF_REF_READ_WRITE on use, in web_main
we should also check all defs with flag DF_REF_READ_WRITE, union it with
corresponding use.


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

* [Bug c++/63157] may_alias doesn't work as expected in template nested types
  2014-09-03 18:47 [Bug c++/63157] New: may_alias doesn't work as expected in template nested types haynberg at sig dot com
  2014-09-04 15:43 ` [Bug c++/63157] " haynberg at sig dot com
@ 2014-09-05  8:48 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-09-05  8:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63157

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to haynberg from comment #2)
> I recently read your old PR about placement new -
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29286.
> 
> Is using placement new also a means to prevent strict-aliasing optimizations
> here?  I don’t think so.  Since the following also aborts.

No, placement new constructs a new object so the contents you read
below are undefined.

> $ cat t.cpp
> #include <memory>
> #include <stdlib.h>
> 
> struct msg {
>    long seq_no;
> };
> 
> void check(char *p)
> {
>    short *a = new (p) short;
>    *a = 5;
> 
>    msg *b = new (p) msg;
>    b->seq_no = 6;
> 
>    a = new (p) short;
>    if (*a == 5)
>      abort();
> }
> 
> int main()
> {
>    msg m[1];
>    check((char*) m);
> }
> $ g++ -O3 -fno-strict-aliasing t.cpp && a.out
> $ g++ -O3 t.cpp && a.out
> Aborted
>From gcc-bugs-return-461280-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Sep 05 09:05:13 2014
Return-Path: <gcc-bugs-return-461280-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 1033 invoked by alias); 5 Sep 2014 09:05:12 -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 987 invoked by uid 48); 5 Sep 2014 09:05:07 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/63181] GCC should warn about "obvious" bugs in binding a reference to temporary
Date: Fri, 05 Sep 2014 09:05: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.9.2
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: redi at gcc dot gnu.org
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-63181-4-UJoZHlUYF4@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63181-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63181-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-09/txt/msg01114.txt.bz2
Content-length: 652

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63181

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. that's not a temporary, it's a named lvalue, but we should definitely
diagnose it.

Since 4.7 GCC does now diagnose similar cases with temporaries resulting from
implicit conversions:

struct Foo {
   Foo(short x): x_(x) { }
   const int& x_;
};

int main()
{
   Foo f(0);
   return f.x_;
}

t.cc: In constructor ‘Foo::Foo(short int)’:
t.cc:2:22: warning: a temporary bound to ‘Foo::x_’ only persists until the
constructor exits [-Wextra]
    Foo(short x): x_(x) { }
                      ^
>From gcc-bugs-return-461283-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Sep 05 09:38:21 2014
Return-Path: <gcc-bugs-return-461283-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 21288 invoked by alias); 5 Sep 2014 09:38:21 -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 20814 invoked by uid 48); 5 Sep 2014 09:38:13 -0000
From: "paolo.carlini at oracle dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/59676] Non-integral glvalues accepted in constant expressions
Date: Fri, 05 Sep 2014 09:38: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.9.0
X-Bugzilla-Keywords: accepts-invalid
X-Bugzilla-Severity: normal
X-Bugzilla-Who: paolo.carlini at oracle dot com
X-Bugzilla-Status: RESOLVED
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: bug_status resolution
Message-ID: <bug-59676-4-0LcP2OHTf9@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-59676-4@http.gcc.gnu.org/bugzilla/>
References: <bug-59676-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: 2014-09/txt/msg01117.txt.bz2
Content-length: 559

https://gcc.gnu.org/bugzilla/show_bug.cgi?idY676

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Same issue, really. Will make sure all the testcases are added.

*** This bug has been marked as a duplicate of bug 57979 ***


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

end of thread, other threads:[~2014-09-05  8:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-03 18:47 [Bug c++/63157] New: may_alias doesn't work as expected in template nested types haynberg at sig dot com
2014-09-04 15:43 ` [Bug c++/63157] " haynberg at sig dot com
2014-09-05  8:48 ` rguenth at gcc dot gnu.org

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