* optimizing variables
@ 2005-09-23 11:06 Jonne Zutt
2005-09-23 11:17 ` John Love-Jensen
0 siblings, 1 reply; 2+ messages in thread
From: Jonne Zutt @ 2005-09-23 11:06 UTC (permalink / raw)
To: gcc-help
Dear gcc experts,
In my simulation tool, I use somebody else's run-time library for a
simulation kernel. This run-time library supports threads by allocating a
local array called 'stackarea' and doing all kinds of stuff and long jumps
etc. I don't quite understand.
The library is used many times, it's stable and all bugs are supposed to
be my own fault.
/* Initialise the array, to fool compilers that it is being
* used, so they don't optimize it away.
* BTW don't write to the entire array, copy-on-write mechanism
* make that very slow. (!)
*/
stackarea[0]=0;
// for(i=1; i<STACKSIZE-1; i++) stackarea[i]=stackarea[i+1];
The system works perfectly fine when compiled without any optimization.
Providing -O for the above file causes a segmentation fault for each
execution very quickly.
Adding the above commented for loop seems to solve this problem.
Now, here's my question:
- I have the feeling this statement stackarea[0]=0 might have fooled gcc
version 3 compiler, but my gcc version 4.0.1 DOES optimize this strange
array away. Is that correct?
- How can I easily check whether a variable has been optimized away, and
how can I avoid this? (e.g. should I write stackarea[random(0,N)] = 0 or
is there a more neat way).
Thanks in advance,
Jonne.
ps >
Just noticed that stackarea[0] = stackarea[STACKSIZE-1] = 0 also does not
"fool" my compiler (i.e. still results in a segmentation fault).
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: optimizing variables
2005-09-23 11:06 optimizing variables Jonne Zutt
@ 2005-09-23 11:17 ` John Love-Jensen
0 siblings, 0 replies; 2+ messages in thread
From: John Love-Jensen @ 2005-09-23 11:17 UTC (permalink / raw)
To: Jonne Zutt, MSX to GCC
Hi Jonne,
I was not able to reproduce the problem you are expriencing. Could you
provide a compilable short example of the problem you are running into.
Please include the command line used to compile the source.
Also, what platform are you using?
Thanks,
--Eljay
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-09-23 11:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-23 11:06 optimizing variables Jonne Zutt
2005-09-23 11:17 ` John Love-Jensen
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).