* [Bug c++/52231] [missed optimization/diagnostics] address-of-reference
2012-02-13 13:33 [Bug c++/52231] New: [missed optimization/diagnostics] address-of-reference pluto at agmk dot net
@ 2012-02-13 17:56 ` pinskia at gcc dot gnu.org
2012-02-13 18:13 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-13 17:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52231
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-02-13 17:56:32 UTC ---
Why do you think this is a missed optimization and/or diagnostic?
References are just like pointers, just &a is really a and a is really *a.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/52231] [missed optimization/diagnostics] address-of-reference
2012-02-13 13:33 [Bug c++/52231] New: [missed optimization/diagnostics] address-of-reference pluto at agmk dot net
2012-02-13 17:56 ` [Bug c++/52231] " pinskia at gcc dot gnu.org
@ 2012-02-13 18:13 ` redi at gcc dot gnu.org
2012-02-13 18:19 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-13 18:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52231
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-02-13
Ever Confirmed|0 |1
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-13 18:13:23 UTC ---
But the language guarantees that for a program without undefined behaviour a
reference is always bound to a valid object.
int* i = nullptr;
int& r = *i; // undefined
if (&r == 0) // cannot be true
;
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/52231] [missed optimization/diagnostics] address-of-reference
2012-02-13 13:33 [Bug c++/52231] New: [missed optimization/diagnostics] address-of-reference pluto at agmk dot net
2012-02-13 17:56 ` [Bug c++/52231] " pinskia at gcc dot gnu.org
2012-02-13 18:13 ` redi at gcc dot gnu.org
@ 2012-02-13 18:19 ` redi at gcc dot gnu.org
2015-02-18 19:36 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-13 18:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52231
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-13 18:19:39 UTC ---
(In reply to comment #1)
> References are just like pointers, just &a is really a and a is really *a.
This is wrong in so many ways.
Pointers can be null, pointers can be uninitialized, pointers can be re-seated.
Would you also argue this shouldn't be optimised?
int i=0;
int& r = i;
// ...
if (&i != &r)
unreachable();
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/52231] [missed optimization/diagnostics] address-of-reference
2012-02-13 13:33 [Bug c++/52231] New: [missed optimization/diagnostics] address-of-reference pluto at agmk dot net
` (2 preceding siblings ...)
2012-02-13 18:19 ` redi at gcc dot gnu.org
@ 2015-02-18 19:36 ` pinskia at gcc dot gnu.org
2015-02-18 19:44 ` froydnj at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-02-18 19:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52231
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |froydnj at gcc dot gnu.org
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 65111 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/52231] [missed optimization/diagnostics] address-of-reference
2012-02-13 13:33 [Bug c++/52231] New: [missed optimization/diagnostics] address-of-reference pluto at agmk dot net
` (3 preceding siblings ...)
2015-02-18 19:36 ` pinskia at gcc dot gnu.org
@ 2015-02-18 19:44 ` froydnj at gcc dot gnu.org
2015-02-18 21:30 ` redi at gcc dot gnu.org
2015-02-18 22:04 ` froydnj at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: froydnj at gcc dot gnu.org @ 2015-02-18 19:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52231
--- Comment #5 from Nathan Froyd <froydnj at gcc dot gnu.org> ---
FWIW, clang (>= 3.5) understands how to optimize the original testcase in
comment 0; it even issues a -Wtautological-undefined-compare warning.
This also showed up in the context of trying to hint to the compiler that
placement new didn't need null checks:
#include <new>
void init(int& p) { new (&p) float(3.14f); }
which clang understands how to optimize and GCC does not.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/52231] [missed optimization/diagnostics] address-of-reference
2012-02-13 13:33 [Bug c++/52231] New: [missed optimization/diagnostics] address-of-reference pluto at agmk dot net
` (4 preceding siblings ...)
2015-02-18 19:44 ` froydnj at gcc dot gnu.org
@ 2015-02-18 21:30 ` redi at gcc dot gnu.org
2015-02-18 22:04 ` froydnj at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2015-02-18 21:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52231
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Nathan Froyd from comment #5)
> This also showed up in the context of trying to hint to the compiler that
> placement new didn't need null checks:
That's only become true quite recently:
http://open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1748
See also PR 35878
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/52231] [missed optimization/diagnostics] address-of-reference
2012-02-13 13:33 [Bug c++/52231] New: [missed optimization/diagnostics] address-of-reference pluto at agmk dot net
` (5 preceding siblings ...)
2015-02-18 21:30 ` redi at gcc dot gnu.org
@ 2015-02-18 22:04 ` froydnj at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: froydnj at gcc dot gnu.org @ 2015-02-18 22:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52231
--- Comment #7 from Nathan Froyd <froydnj at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> (In reply to Nathan Froyd from comment #5)
> > This also showed up in the context of trying to hint to the compiler that
> > placement new didn't need null checks:
>
> That's only become true quite recently:
> http://open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1748
Ah, thanks for the pointer. I assumed that the compiler would be able to infer
that |&reference| would be non-null and eliminate the mandatory check
regardless, but it's nice to have spec language to back this up.
> See also PR 35878
Again, thanks for the pointer. If we can do this in the frontend now, that
might be simple enough that I could take a look at it myself (assuming it
hasn't been done and that PR simply didn't get referenced).
^ permalink raw reply [flat|nested] 8+ messages in thread