[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::decc_bugs

Title:DEC C Problem Reporting Forum
Notice:Report DEC C++ problems in TURRIS::C_PLUS_PLUS
Moderator:CXXC::REPETETCHEON
Created:Fri Nov 13 1992
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1299
Total number of notes:6249

1264.0. "setjmp/longjmp problem" by UTRTSC::WDEBAKKER (Feed your head) Mon Feb 17 1997 07:38

Hello,

A customer reported a problem with setjmp/longjmp, which is
reproducable with DEC C V5.5-002 on OpenVMS Alpha V6.2.
It works fine, however, with DEC C V5.5-002 and OpenVMS VAX V6.2
Below is a short reproducer.

Any ideas how this could be solved?
Thanks in advance,
Willem de Bakker


/*
 * Copyright, Fuji Photo Film B.V, Tilburg
 *
 * DESCRIPTION
 *   Description of incorrect behaviour of the DECC compiler when
 *   volatile variables should not be optimized.
 *
 *   According to the DECC run time library reference manual:
 *   "The setjmp function preserves the hardware general pur-
 *    pose registers, and the longjmp function restores them. After
 *    a longjmp, all variables have their values as of the time of
 *    the longjmp except for local automatic variables not marked
 *    volatile. These variables have indeterminate values"
 *
 *   In short: In the example below MyCharp must preserve its value which it
 *   does not.
 *   Compiled, linked and run as:
 *   $ CC/DEBUG/NOOPTIMIZE <file>
 *   $ LINK <file>
 *   $ RUN <file>
 *   MyCharp: 0 (null)
 *
 *   The behaviour was introduced when upgrading from AXP DECC
 *   v4.1 to v5.2 and continues to exist in DECC v5.5.
 *   In the v4.1 era, the compiler did not use any registers at all
 *   if /DEBUG/NOOPTIMIZE were passed as options. From v5.2 on it does, even
 *   when not allowed.
 *
 *   Kind regards,
 *
 *   Arie van Wijngaarden
 *   e-mail: [email protected]
 * HISTORY
 *   17-FEB-1997, AvW
 *      Created.
 */

#include <stdio.h>
#include <setjmp.h>

int main()
{
   volatile const char *MyCharp = 0;
   jmp_buf JumpContext;

   if (setjmp(JumpContext) == 0)
   {
      MyCharp = "Hallo boppers";
      longjmp(JumpContext, 1);
   }
   printf("MyCharp: %x %s\n", MyCharp, (MyCharp) ? MyCharp : "(null)");
}
T.RTitleUserPersonal
Name
DateLines
1264.1Confusing placement of volatileWIBBIN::NOYCEPulling weeds, pickin&#039; stonesMon Feb 17 1997 08:496
>    volatile const char *MyCharp = 0;

This declares that MyCharp is a pointer to a volatile const char.
You probably wanted MyCharp to be volatile itself:

const char * volatile MyCharp = 0;
1264.2UTRTSC::WDEBAKKERFeed your headMon Feb 17 1997 08:5818
Thanks,

but is the code in .0 incorrect?
As it worked fine on the VAX platform, and it used to
work with DEC C V4.2, the customer's likely to
point to the upgrade to DEC C V5
He wrote to me:
After upgrading from DECC v4.2 to 5.x a problem arised when using
setjmp/longjmp combinations in C sources. According to the documentation,
a longjmp may influence the values of the local automatic variables
which are not marked volatile. However, it also influences the values
for automatic pointer variables declared volatile (see example below).
Note that the behaviour is correct for automatic int variables declared
volatile as well as variables declared static or extern.

Thanks,
Willem
1264.3Yes, the code in .0 is incorrect.WIBBIN::NOYCEPulling weeds, pickin&#039; stonesMon Feb 17 1997 09:254
The customer *doesn't have* a pointer variable declared volatile.

Since MyCharp in .0 is not volatile, its value after longjmp is
indeterminate.
1264.4DECCXL::OUELLETTEWed Feb 19 1997 17:007
Just to add a nail to the coffin...

With the old compilers, your customer's indeterminate value
hid your coustomer's bug.  Their code needs to be fixed to work
by forcing a determinate value.

R.
1264.5Dig itUTRTSC::WDEBAKKERFeed your headThu Feb 20 1997 03:146
OK, Thanks for your replies.

I'll see to it that this coffin gets buried

Cheers,
Willem