Program crashes with optimization level O2
I am experiencing a difficulty undersatnding why my program (C++, HP UNIX) crashes. It crashes only when I build it with -O (+O2) optimization switch (used in aCC compiler). It works ok with +O0 or +O1 optimization.
Also, I see that local variables are shown incorrecly when program is built with +O2 optimization switch. They show correcly with +O0 or +O1 optimization.
Could anyone advise me on the +O2 optimization? Why this could lead to the crash? Why the debugger fails to show correctly the local variables?
It is compiled with the following switches:
/opt/aCC/bin/aCC -AA -DHPUX -DBUILD_UNIX -DNO_MSG_BUILD -DNO_MAP_BUILD -DUNICODE -DPIC +Z +inst_auto -D_THREADSAFE -mt +W641 +W829 -g0 -O -I.. -I../.. -I../lib -I/usr/local/include/stl -I../pcmsrv32 -I../pcmlib -g0 -c
Below is the gdb output after the crash:
Program received signal SIGSEGV, Segmentation fault.
0x7f0cc484 in GetAddress (grid=0, link=0, rAddress=@0x0) at street.cpp:352
352 street.cpp: No such file or directory.
(gdb) backtrace
#0 0x7f0cc484 in GetAddress (grid=0, link=0, rAddress=@0x0) at street.cpp:352
#1 0x7f2409d8 in LRAddrOutput::AddressSearch (this=0x7f7f41e8, pInterp=0x0,
grid=13, oldNumMatches=2132813148, rLinkJuris=@0x7f7f41cc,
rPostalCodes=@0x7f7f41e8, rLinkInfo=@0x7f7f4178, rNameInfo=@0x7f7f4194,
exact=@0x7f7f4078) at geoaddrs.cpp:3845
#2 0x7f23e450 in LRAddrOutput::SearchForAddress (this=0x7f7f3fe0, gridID=0,
pInterp=0x401be934, exact=@0x7f129158) at geoaddrs.cpp:2887
#3 0x7f232b88 in LRAddrOutput::CalcMatches (this=0x0, pCB=0x0)
at geoaddrs.cpp:559
#4 0x7f244664 in LRAddr::Lookup (this=0x694, region=0x0,
state=0x3 <Error reading address 0x3: Invalid argument>, pCB=0x0)
at geoaddrs.cpp:4901
#5 0x7f24beb0 in CGeocoder::FindStreetMatchesW (this=0x4004cd7c,
addrW=0x4004cd38 "\177\026\357\b", cityW=0x401be3a4 "", stateW=0x0,
countyW=0x401be934 "", zipW=0x401be9b4 "", size=0 '\000', grid=7026188,
pCB=0x0, type=0, lLat=0, lLong=0) at geocoder.cpp:1044
#6 0x7f2a21d4 in Place_NumAddressMatches (geoID=2139042812,
inStr=0x7f7f33f0 "",
city=0xffffffff <Error reading address 0xffffffff: Bad address>,
state=0x0, county=0x401be934 "", zip=0x401be9b4 "", size=0 '\000',
grid=7026188, UpdateProgMeter=0) at placemgr.cpp:957
#7 0x7f30d5d4 in GeoCodeImpl::NodeForCityOrAddr (this=0x7f7f3300,
pGeoResults=0x7f2b8430, pszLookup=0x4000f608 "NA", bExactMatch=96,
bSPLC=false, bRdNameOnly=false) at geo_impl.cpp:542
---Type <return> to continue, or q <return> to quit---
#8 0x7f30df4c in GeoCodeImpl::Nodefor (this=0x401be370,
pszLookup=0x3 <Error reading address 0x3: Invalid argument>,
bExactMatch=-56, returnSPLC=96, pRtOptions=0x40009e78,
bTrySupressPicklist=false) at geo_impl.cpp:687
#9 0x7f336774 in RouteImpl::AddStop (this=0x401b7f58,
name=0x400c17ec "\177+g@t\nfin=CoPilot tiedostotiedot\nfre=Informations sur
le Fichier CoPilot\nger=CoPilot Dateiinformationen\ngre=\316\240\316\273\316\267
\317\201\316\277\317\206\316\277\317\201\316\257\316\265\317\202 \316\263\316\27
1\316\261 \317\204\316\277 \316\261\317\201\317\207\316\265\316\257\316\277 CoPi
lot\nita=Informazioni sui file di CoPilot"..., gc=0x7f7f31b0)
at route_impl.cpp:488
#10 0x7f39915c in PCMSAddStop (trip=333240,
stop=0x5159c "PCMSAddStop returned %d\n") at pcmsrvapp.cpp:1312
#11 0x266b8 in TestFuelOpt () at pcmstest.cpp:616
#12 0x25ae4 in main () at pcmstest.cpp:467
(gdb)
Any help is appreciated.