www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/04/23/06:20:10

Date: Sun, 23 Apr 1995 17:51:18 +0900
From: Stephen Turnbull <turnbull AT shako DOT sk DOT tsukuba DOT ac DOT jp>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: More optimization woes...

   Hi all:
   This may not be a djgpp problem (if not, tell me so and where to gripe) 
   but here it is:

Does it work correctly under gdb and without debugging?  If so, the
chance that it's edebug (which is djgpp-specific) rises drastically.

   I have a program that uses inline (eg _farptr) functions, so I want to 
   compile with optimization (-O or -O2).  However, I am getting some weird 
   code generation, viz:

   int ListProc (WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2) {
   [snip]
       switch (msg) {
	   case CREATE_WINDOW:
	       wnd->ct = DFmalloc(sizeof(CTLWINDOW));

The compiler is *not* allowed to move any following references to
wnd->ct before this line.  Look at the assembler output when compiled
with and without optimization.  (You can isolate the whole function in
a separate file so it's the only one; to see the assembler, use "gcc
-S" (that's an upper-case 'S'; I believe the output from file.c ends
up in file.i by default but I'm not sure).

If it in fact it is doing so, it's a GCC or DJGPP bug (likely the
former).

	       wnd->ct->setting = OFF;	// line 53
   [snip]

   Under edebug32, it seems that line 53 is the first line that is executed; 
   the DFmalloc() line is not executed, and so wnd->ct is NULL and so 
   dereferencing it produces an exception.

You have checked that DFmalloc() is not in fact producing a NULL
pointer for some reason, I assume.  But if it were me, the assumption
might be false---last head-scratcher that bit me was very similar :-)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019