[Bug tree-optimization/16179] useless copies not optimized away
rguenth at tat dot physik dot uni-tuebingen dot de
gcc-bugzilla@gcc.gnu.org
Thu Jun 24 18:30:00 GMT 2004
------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de 2004-06-24 18:26 -------
Subject: Re: useless copies not optimized away
pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-24 17:57 -------
> This is not a bug, as bar could change f at any time.
> So lets examine the code:
> extern void bar(void);
>
> int foo(const int &f)
> {
> const int a = f; <-- load *f
> int c = a; <-- move into c from a (all local to foo, c is not take the address of so it cannot be
> aliased, likewise for a)
> bar(); <-- call bar, can change *f
> c = a; <-- move into c from a (all local to foo again)
> return c; <-- return the value in c
> }
>
> int foo2(const int &f)
> {
> int c = f; <-- load *f into c
> bar(); <-- call bar, can change *f
> c = f;<-- load *f into c
> return c;
> }
>
> So these two code cannot be equivant at all.
>
I think they are - if bar() modifies f, the behavior is undefined as of
6.7.3.5 (C99), 7.1.5.1.4 (C++). Not?
If they are _not_ the same, if I want to enforce const-ness for the
optimizers, I need to place local copies of arguments so the compiler
can tell from aliasing that modification cannot take place?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16179
More information about the Gcc-bugs
mailing list