GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 13028 - ia64 gcc with -O2 does not store value in register into local varible
Summary: ia64 gcc with -O2 does not store value in register into local varible
Status: RESOLVED DUPLICATE of bug 21920
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-12 21:53 UTC by Xiaolin Zang
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Xiaolin Zang 2003-11-12 21:53:58 UTC
This can be demonstrated with the following sample program:

/*
 * program starts
 */

#define ntoh64(_src_, _dest_) { \
  unsigned int *src_p = (unsigned int *) _src_;   \
  unsigned int *dest_p = (unsigned int *) _dest_; \
    *dest_p++ = *src_p++; \
    *dest_p++ = *src_p++; \
}

void
call(unsigned long *number_p)
{
  unsigned long seqno;

  ntoh64(number_p, &seqno);

  printf("in reply_received: seqno is %lu\n", seqno);

  printf("in reply_received: seqno is %lu\n", seqno);
}

main() {
  unsigned long number = 1010101;
  call(&number);
}

/*
 * program ends
 */

The following is the compile command line:

[build-hp1] gcc -v -save-temps -O2 compiler.c 
Reading specs from /usr/lib/gcc-lib/ia64-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2)
 /usr/lib/gcc-lib/ia64-redhat-linux/2.96/cpp0 -lang-c -v -D__GNUC__=2
-D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ia64 -D__ia64__ -D__linux
-D__linux__ -D_LONGLONG -Dlinux -Dunix -D__LP64__ -D__ELF__ -D__ia64 -D__ia64__
-D__linux -D__linux__ -D_LONGLONG -D__linux__ -D__unix__ -D__LP64__ -D__ELF__
-D__linux -D__unix -Asystem(linux) -Acpu(ia64) -Amachine(ia64) -D__OPTIMIZE__
-D__LONG_MAX__=9223372036854775807L compiler.c compiler.i
GNU CPP version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2) (cpplib) (IA-64)
ignoring nonexistent directory "/usr/ia64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc-lib/ia64-redhat-linux/2.96/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/ia64-redhat-linux/2.96/cc1 compiler.i -mb-step -quiet
-dumpbase compiler.c -O2 -version -o compiler.s
GNU C version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2) (ia64-redhat-linux)
compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2).
 as -x -o compiler.o compiler.s
 /usr/lib/gcc-lib/ia64-redhat-linux/2.96/collect2 -dynamic-linker
/lib/ld-linux-ia64.so.2 /usr/lib/gcc-lib/ia64-redhat-linux/2.96/../../../crt1.o
/usr/lib/gcc-lib/ia64-redhat-linux/2.96/../../../crti.o
/usr/lib/gcc-lib/ia64-redhat-linux/2.96/crtbegin.o
-L/usr/lib/gcc-lib/ia64-redhat-linux/2.96
-L/usr/lib/gcc-lib/ia64-redhat-linux/2.96/../../.. compiler.o -lgcc -lc -lgcc
/usr/lib/gcc-lib/ia64-redhat-linux/2.96/crtend.o
/usr/lib/gcc-lib/ia64-redhat-linux/2.96/../../../crtn.o

The following is the run of the generated program:

[build-hp1] a.out
in reply_received: seqno is 0
in reply_received: seqno is 1010101
Comment 1 Andrew Pinski 2003-11-12 22:02:36 UTC
Not a bug as the types unsigned int and unsigned long are know not to alias (really their pointers 
are) each other.  Also you are using an old version of gcc (2.96 a non-supported one at that), try to 
update it.
Comment 2 Xiaolin Zang 2003-11-14 15:18:06 UTC
It's debatable whether this is a bug but this is certainly a limitation.  Is
this documented anywhere?

By the way I hope you at least try the sample program with your newer version of
gcc to see if it's fixed.  That should only take you minutes.  To download and
compile the compiler would take me at least hours.  Thanks.
Comment 3 Andreas Schwab 2003-11-14 15:29:00 UTC
Look up -Wstrict-aliasing in the manual. 
Comment 4 Dara Hazeghi 2003-12-09 23:10:57 UTC
As pointed out, you're violating strict aliasing rules. With gcc 3.3:

bash-2.05a$ gcc -Wall -O3  bug.c 
bug.c: In function `call':
bug.c:17: warning: dereferencing type-punned pointer will break strict-aliasing rules

If you want this to work, you'll have to compile with -fno-strict-aliasing, in which case it does 
work, at least with 3.3.
Comment 5 Xiaolin Zang 2003-12-10 12:02:45 UTC
thanks for the info.  I'll close this bug and we'll upgrade our gcc when it's 
the right time.  Our engineers are warned about the risk aliasing types of 
different sizes when using optimization.
Comment 6 Dara Hazeghi 2003-12-10 17:58:03 UTC
Please don't mark bugs as closed...
Comment 7 Dara Hazeghi 2003-12-10 17:58:48 UTC
mark as "resolved invalid" (bugzilla consistency reasons).
Comment 8 Andrew Pinski 2005-06-05 08:32:40 UTC
Reopening to ...
Comment 9 Andrew Pinski 2005-06-05 08:32:57 UTC
Mark as a dup of bug 21920.

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