Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: coates@kelvin.physics.uq.oz.au (Tony Coates)
Subject: Re: DEC AXP (Alpha) c89 bug
Date: 18 Mar 94 11:14:45	[thread overview]
Message-ID: <COATES.94Mar18111445@kelvin.physics.uq.oz.au> (raw)
In-Reply-To: cmr@world.std.com's message of Thu, 17 Mar 1994 11:37:50 GMT

In article <CMt4B2.CBr@world.std.com> cmr@world.std.com (Charles M
Richmond) writes:

   coates@kelvin.physics.uq.oz.au (Tony Coates) (*me*) writes:

   >We just received the DEC AXP (Alpha) c89 compiler as part of DEC's cxx
   >C++ compiler package.  We are running OSF/1.3.  I tried recompiling an
   >old program which compiled under cc and ran correctly.  However, after
   >compilation with c89, the program failed.  Debugging with dbx, and
   >with the aid of a few printf statements which I had to add, I found
   >that, when compiled with c89, a switch statement of the form

   >	switch(<function evaluation>) {
   >	case -1: <blah>; break;
   >	case  1: <blah>; break;
   >	default: <blah>
   >        }

   >was reaching the default statement, even though the function
   >evaluation yielded -1.  The same statement selected the -1 case when
   >compiled with cc.

   If you would provide us with an "actual" failing case (bad pun) then
   the net might be able to help.  I would guess that your function
   evaluation and your case data use different types. Personally, I
   like c89.

Well, I didn't provide the actual case, because I thought it too long,
but I will now.  The function returns a `signof' value - if this isn't
an integer, then I'll be amused.  The evalutaion is a bit compicated,
but runs as follows.  The switch that fails looks like

    switch(key_compare(p_tbky,p_tb->ca_p_parent->p_key))
      {
       case -1: p_tb->ca_p_parent->p_left =p_new; break;
       case  1: p_tb->ca_p_parent->p_right=p_new; break;
       default: as_bomb("tb_ins: Key comparison function is inconsistent.");
      }
 
and runs through to the default case when the function returns -1
(only under c89, not under cc.  It works under cc).

keycompare is a macro, defined as follows:

#define key_compare(a,b) ((*(p_tb->p_kycm))((a),(b)))

The particular function `p_kycm' which is called in the failing case
is the following:

LOCAL sign cm_name P_((name_t *,name_t *));
LOCAL sign cm_name(name1,name2)
/* Compares two names and returns:               */
/*    -1 if name1 < name2                        */
/*     0 if name1 = name2                        */
/*     1 if name1 > name2                        */
/* Provides a full ordering on the set of names. */
name_t *name1;
name_t *name2;
{
 return signof(strcmp(&(*name1)[0],&(*name2)[0]));
}

where the P_ macro just serves here to create an ANSI prototype,
and the name_t structure is a fixed length array of characters.

	As I noted, this fails when compiled under c89, not cc, on a
DEC AXP running OSF/1.3.  I haven't attempted to try to convert this
to a trivial example to check under what conditions it can occur,
because changing back from c89 to cc is less effort for me than trying
to create an example where it fails.  Given that switch statements
usually work, I can only hypothesise that this is a bug which doesn't
arise in simple test programs, only in larger programs.
					Cheers,
							Tony.
--
_____________________________________________________________________________
A.B.Coates, Dept. of Physics,
The University of Queensland  QLD  4072  Australia.
Email: coates@physics.uq.oz.au
Phone: (07/+617) 365-3424  Fax: (07/+617) 365-1242
Disclaimer: The University is ignorant of my
            opinions, let alone guilty ...
_____________________________________________________________________________


  reply	other threads:[~1994-03-18 16:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-03-17 16:16 DEC AXP (Alpha) c89 bug Tony Coates
1994-03-17 11:37 ` Charles M Richmond
1994-03-18 16:14   ` Tony Coates [this message]
1994-03-17 22:45 ` Holger Rasch
1994-03-22 16:27   ` Andre Beck
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox