This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/16179] useless copies not optimized away
- From: "rguenth at tat dot physik dot uni-tuebingen dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Jun 2004 18:26:05 -0000
- Subject: [Bug tree-optimization/16179] useless copies not optimized away
- References: <20040624175318.16179.rguenth@tat.physik.uni-tuebingen.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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