User account creation filtered due to spam.

Bug 17998 - Pointer reference optimized into register is not used when referenced through type cast.
Summary: Pointer reference optimized into register is not used when referenced through...
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.2
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2004-10-14 12:30 UTC by Artur Zaprzala
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:

Testcase (98 bytes, text/plain)
2004-10-14 12:35 UTC, Artur Zaprzala

Note You need to log in before you can comment on or make changes to this bug.
Description Artur Zaprzala 2004-10-14 12:30:39 UTC
void test(int *&p) {
  p+= 1; // modifies p in register
  (char*&)p+= 8; // modifies p in memory
  // finally the value from register wins

This prints 4 (BAD):
g++ -O2 -march=athlon -o bug; ./bug; echo $?

This prints 12 (CORRECT):
g++ -O1 -march=athlon -o bug; ./bug; echo $?

This prints 12, but works by chance (assembly code is incorrect):
g++ -O2 -o bug; ./bug; echo $?

# gcc -v
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041006 (Red Hat 3.4.2-5)
Comment 1 Artur Zaprzala 2004-10-14 12:35:09 UTC
Created attachment 7350 [details]
Comment 2 Wolfgang Bangerth 2004-10-14 13:01:46 UTC
You can't do that -- your code violates aliasing rules. 
Comment 3 Andrew Pinski 2005-06-05 09:00:57 UTC
Reopening to ...
Comment 4 Andrew Pinski 2005-06-05 09:01:13 UTC
Mark as a dup of bug 21920

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