public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "glisse at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/64601] Missed PRE on std::vector move assignment
Date: Sat, 17 Jan 2015 13:04:00 -0000	[thread overview]
Message-ID: <bug-64601-4-06vWkymvg6@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-64601-4@http.gcc.gnu.org/bugzilla/>

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #9 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #8)
> The transformation is triggered by dereferences, and compares the types of
> objects, not pointers, so it isn't obvious that the issues you were
> describing apply to it.

It looks like they still do apply. I was just lucky that the folding was done
in an order where nothing bad happened in the tests. Your example

 int *p = &((struct A *)&b)->i;
 *p = 0;

becomes *(int*)&b=0, which is fine. But in a different order, what I wanted
could give: (*(struct A *)&b).i=0 (access b as an A) which would be wrong for
TBAA. Although I don't see the point of writing that kind of code instead of:

 int *p = (int*)((char*)&b + offsetof(A, i));

So basically, a struct A * as an argument of a function doesn't carry any more
information than a void* :-( It is only if we can see an actual VAR_DECL or
similar that we may be able to reconstruct the access, but then we don't often
need to...

It is strange that [basic.lval] (or 6.5 Expressions in C99) is so lenient.
[class.mem] is a little bit more restrictive but still not much.

There is a little bit of divergence on function f below:

void f(struct A *a){ *&a->i=0; }
void g(struct A *a){ int*p=&a->i;*p=0; }
void h(struct A *a){ a->i=0; }

gcc, intel and oracle handle f like h, while clang is more conservative and
handles it like g (I actually tested on a function taking 2 std::pair<int,int>
by reference if a.first and b.second could alias).

Ok, I am starting to understand vaguely what C/C++ are saying about type
aliasing. I am horrified (this is a huge abstraction penalty), but at least I
am less confused. I'll close this PR as INVALID (the trick about the same
clobbering value is already in several other PRs, no need to keep this one as
well) (if you want to remove some current unsafe transformations, it would
probably be less confusing to open a different PR).

I wonder how feasible it would be to define a dialect where any non-zero struct
A* really points to a struct A... (we already have void* and char* for
"untyped" pointers)


      parent reply	other threads:[~2015-01-17 13:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14 20:12 [Bug tree-optimization/64601] New: " glisse at gcc dot gnu.org
2015-01-15  9:44 ` [Bug tree-optimization/64601] " rguenth at gcc dot gnu.org
2015-01-15 19:53 ` glisse at gcc dot gnu.org
2015-01-15 22:37 ` glisse at gcc dot gnu.org
2015-01-16  9:25 ` rguenth at gcc dot gnu.org
2015-01-16  9:26 ` rguenth at gcc dot gnu.org
2015-01-16  9:39 ` rguenth at gcc dot gnu.org
2015-01-16  9:52 ` glisse at gcc dot gnu.org
2015-01-16 15:30 ` glisse at gcc dot gnu.org
2015-01-17 13:04 ` glisse at gcc dot gnu.org [this message]

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-64601-4-06vWkymvg6@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).