public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26767] New: Optimization level -O3 changes the program behavior
@ 2006-03-20 9:58 mor_gopal at yahoo dot com
2006-03-20 10:00 ` [Bug c++/26767] " mor_gopal at yahoo dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: mor_gopal at yahoo dot com @ 2006-03-20 9:58 UTC (permalink / raw)
To: gcc-bugs
Following program generates different outputs for -O1 and -O3 optimization
levels.
#include <stdio.h>
typedef struct _airInfo{
unsigned int craftNo : 16;
unsigned int onAir:1;
unsigned int numCrew:2;
unsigned int numPassenger:2;
unsigned int onLand:1;
unsigned int fuelTank:2;
unsigned int height: 8;
} airInfo_t ;
#pragma pack(1)
typedef struct _atmosphere {
int temp:24;
int humidity:24;
int pressure:24;
int altitude:24;
}atmosphere_t;
typedef struct _mixedInfo {
airInfo_t ai;
atmosphere_t atm;
}mixedInfo_t;
#pragma pack()
int main() {
mixedInfo_t mi ;
mi.ai.height = 17;
mi.ai.craftNo = 1;
mi.ai.onAir = 0;
mi.ai.numCrew = 2;
mi.ai.numPassenger = 2;
mi.ai.onLand = 0;
mi.ai.fuelTank = 0;
printf("ai in num = %u\n", (*((unsigned int *)(&mi.ai)))) ;
return 0 ;
}
// Output from program when compiled with -O1
$ g++ -O1 test1.cxx ; ./a.out
ai in num = 286523393
// Output from program when compiled with -O3
$ g++ -O3 test1.cxx ; ./a.out
ai in num = 1310720
--
Summary: Optimization level -O3 changes the program behavior
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mor_gopal at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26767
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/26767] Optimization level -O3 changes the program behavior
2006-03-20 9:58 [Bug c++/26767] New: Optimization level -O3 changes the program behavior mor_gopal at yahoo dot com
@ 2006-03-20 10:00 ` mor_gopal at yahoo dot com
2006-03-20 10:08 ` rguenth at gcc dot gnu dot org
2006-03-22 5:26 ` mor_gopal at yahoo dot com
2 siblings, 0 replies; 4+ messages in thread
From: mor_gopal at yahoo dot com @ 2006-03-20 10:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from mor_gopal at yahoo dot com 2006-03-20 10:00 -------
Following details are added.
// g++ version info
$ g++ -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.3/specs
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=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.1)
// System info
$uname -a
Linux NEW1_dev_opteron 2.6.9-11.EL #1 Fri May 20 18:15:25 EDT 2005 x86_64
x86_64 x86_64 GNU/Linux
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26767
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/26767] Optimization level -O3 changes the program behavior
2006-03-20 9:58 [Bug c++/26767] New: Optimization level -O3 changes the program behavior mor_gopal at yahoo dot com
2006-03-20 10:00 ` [Bug c++/26767] " mor_gopal at yahoo dot com
@ 2006-03-20 10:08 ` rguenth at gcc dot gnu dot org
2006-03-22 5:26 ` mor_gopal at yahoo dot com
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-03-20 10:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2006-03-20 10:08 -------
*** This bug has been marked as a duplicate of 21920 ***
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26767
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/26767] Optimization level -O3 changes the program behavior
2006-03-20 9:58 [Bug c++/26767] New: Optimization level -O3 changes the program behavior mor_gopal at yahoo dot com
2006-03-20 10:00 ` [Bug c++/26767] " mor_gopal at yahoo dot com
2006-03-20 10:08 ` rguenth at gcc dot gnu dot org
@ 2006-03-22 5:26 ` mor_gopal at yahoo dot com
2 siblings, 0 replies; 4+ messages in thread
From: mor_gopal at yahoo dot com @ 2006-03-22 5:26 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from mor_gopal at yahoo dot com 2006-03-22 05:25 -------
The following keywords are added to this page, so that developers facing
similar problem can search (hopefully) this page using search engines.
bitfield problem bug gcc g++ optimization bit field strict aliasing ISO C
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26767
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-03-22 5:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-20 9:58 [Bug c++/26767] New: Optimization level -O3 changes the program behavior mor_gopal at yahoo dot com
2006-03-20 10:00 ` [Bug c++/26767] " mor_gopal at yahoo dot com
2006-03-20 10:08 ` rguenth at gcc dot gnu dot org
2006-03-22 5:26 ` mor_gopal at yahoo dot com
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).