public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Jonne Zutt" <j.zutt@ewi.tudelft.nl>
To: gcc-help@gcc.gnu.org
Subject: optimizing variables
Date: Fri, 23 Sep 2005 11:06:00 -0000	[thread overview]
Message-ID: <50944.82.210.115.35.1127473557.squirrel@webmail.isa.ewi.tudelft.nl> (raw)


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).

             reply	other threads:[~2005-09-23 11:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-23 11:06 Jonne Zutt [this message]
2005-09-23 11:17 ` John Love-Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50944.82.210.115.35.1127473557.squirrel@webmail.isa.ewi.tudelft.nl \
    --to=j.zutt@ewi.tudelft.nl \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).