public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31949] New: SH- Aliasing problem for incompatible pointers in c code
@ 2007-05-16 11:55 Ashay dot Jaiswal at kpitcummins dot com
2007-05-16 14:24 ` [Bug c/31949] " rguenth at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: Ashay dot Jaiswal at kpitcummins dot com @ 2007-05-16 11:55 UTC (permalink / raw)
To: gcc-bugs
Hello all,
I have successfully built SH4-Linux toolchain based on
(binutils-2.17, gcc-4.2-20061205, glibc-2.5) for Renesas SH target.
I am facing problem while executing the following C program.
------------------------------------------------------------------
#include <stdio.h>
struct structB { int x; int y; };
struct structC { int x; int y; };
main()
{
struct structC varCs, *varCp=&varCs, **varCpp=&varCp;
struct structB *varBp;
varCs.x = 10;
varCs.y = 20;
varBp = *((struct structB **)varCpp);
varBp->x = varBp->y;
printf("%d",varCs.x);
}
------------------------------------------------------------------
The above program compiles successfully with the sh4-linux toolchain.
While executing on target platform it is generating wrong result.
Observations:
1. When the above program is compiled with '-O0' optimization the value of
varCs.x is printed as 20, which is the expected output.
Command: sh4-linux-gcc <file name>
2. When the above program is compiled with '-O2' optimization the program is
giving following errors:
a) "Bus error" when executed on SH7780 Highlander board.
b) "Killing process due to unaligned access in user space" when executed on
SH7751 R2D board.
Command: sh4-linux-gcc -O2 <file name>
3. When the above program is compiled with '-O2' and '-fno-strict-aliasing'
option the value of varCs.x is printed as 20.
Command: sh4-linux-gcc -O2 -fno-strict-aliasing <file name>
Is the above problem related to strict aliasing ? As with 'fno-strict-aliasing'
option the above code works fine.
Any help on this will be appreciated.
Regards,
Ashay Jaiswal
KPIT Cummins Infosystems Ltd,
Pune (INDIA)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based SH-Linux toolchains for Renesas' SH Series.
The following site also offers free technical support to its users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU SH-Linux tools were released on April 5, 2007.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
Summary: SH- Aliasing problem for incompatible pointers in c code
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Ashay dot Jaiswal at kpitcummins dot com
GCC build triplet: i686-pc-gnu
GCC host triplet: sh4-unknown-linux
GCC target triplet: sh4-unknown-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31949
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/31949] SH- Aliasing problem for incompatible pointers in c code
2007-05-16 11:55 [Bug c/31949] New: SH- Aliasing problem for incompatible pointers in c code Ashay dot Jaiswal at kpitcummins dot com
@ 2007-05-16 14:24 ` rguenth at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-05-16 14:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2007-05-16 15:24 -------
You are accessing memory of type structC via a pointer of type structB * which
violates C aliasing rules.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31949
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-05-16 14:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-16 11:55 [Bug c/31949] New: SH- Aliasing problem for incompatible pointers in c code Ashay dot Jaiswal at kpitcummins dot com
2007-05-16 14:24 ` [Bug c/31949] " rguenth at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).