www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/13/04:20:18

From: "Anthony.Appleyard" <MCLSSAA2 AT fs2 DOT mt DOT umist DOT ac DOT uk>
Organization: Materials Science Centre
To: DJGPP AT delorie DOT com
Date: Fri, 13 Mar 1998 09:16:45 GMT
Subject: Clobbered
Reply-to: Anthony DOT Appleyard AT umist DOT ac DOT uk
Message-ID: <57D90ADC@fs2.mt.umist.ac.uk>

  <Please reply to me personally also, as I again have had to unsubscribe from
djgpp because of severe email intray overload. Sorry. (P.S. As I write this,
my email server is down yet again).>

  What the rules for deciding whether longjmp may `clobber' a particular local
variable or a `*this'? (I never use vfork().) For example, the function
hereinunder (part of a text editor that I wrote and often use) causes these
two warnings when compiled with -O2:-
  (1) macros.cc:579: warning: variable `int b' might be clobbered by `longjmp'
or `vfork'
  (2) macros.cc:579: warning: variable `int nn' might be clobbered by
`longjmp' or `vfork'

  Of three local variables involved, the warning seems inappropriate:-
  <nn>: is set or altered once only, completely before any part of the longjmp
apparatus occurs. What is the compiler talking about at (2)??
  <b>: O.K. I do alter b if longjmp occurs. But that is intended, so that the
instructions after label BAD: can tell whether control is there because of a
longjmp().
  <n>: is altered after the call of setjmp() but I get no `clobbered' warning.

//// Breakin() == 1 if the user is pressing ctrl-alt-leftshift
/*-----*/
void macro::operator()(val N/*=val(1,0)*/,int r/*=0*/){(r=r);/***/
int b=0,nn=N.n==_int?N.i:1; strings*S,*T;
val *p; int i,n; macstep*A; macrinfo MI,*oldmi=mi; mi=&MI; G();
jmp_buf*oldbad=bad,failed; bad=&failed; if(setjmp(*bad)) {b=1; goto BAD;}
if((n=nvars)) {p=mi->stack=new val[mi->nvars=n]; for(i=0;i<n;i++) p[i]=val();}
if(macdepth++>16) {Moan="macro calls >16 deep"; goto BAD;}
for(i=0;jump=0,Breakin()?0:i<nn;i++)
  for(A=text,MI.prevstep=&_lazy;A;A=jump?:A->next){
    MI.rec=1;
    jump=0;
    (*A)(); /* this function calls longjmp() */
    mi=&MI;
    if(MI.rec) MI.prevstep=A; if(Breakin()) goto BAD;}
BAD: for(i=0;i<mi->nvars;i++) mi->stack[i].del();
T=MI.delenda; while((S=T)) {T=S->next; delete S->s; delete S;}
macdepth--; mi=oldmi; bad=oldbad;
if(b) MOAN(Moan); /* this macro calls longjmp() */ }

- Raw text -


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