[m-dev.] for review: fix RTTI bug affecting large stack frames

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Dec 10 15:14:11 AEDT 2001


On 10-Dec-2001, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> +++ runtime/mercury_layout_util.c	2001/12/07 07:02:01
> @@ -166,8 +166,10 @@
>  	}
>  }
>  
> +#ifdef	MR_DEBUG_LVAL_REP
>  /* if you want to debug this code, you may want to set this var to TRUE */
> -static	bool	MR_print_locn = FALSE;
> +static	bool	MR_print_locn = TRUE;
> +#endif
>  
>  MR_Word
>  MR_lookup_long_lval(MR_Long_Lval locn, MR_Word *saved_regs, bool *succeeded)
> @@ -193,69 +195,90 @@
>  	locn_num = (int) MR_LONG_LVAL_NUMBER(locn);
>  	switch (MR_LONG_LVAL_TYPE(locn)) {
>  		case MR_LONG_LVAL_TYPE_R:
> +#ifdef	MR_DEBUG_LVAL_REP
>  			if (MR_print_locn) {
> -				printf("r%d", locn_num);
> +				printf("closure r%d\n", locn_num);
>  			}
> +#endif

It would be better to define MR_print_locn as a constant,
i.e.

	#ifdef	MR_DEBUG_LVAL_REP
	    static const bool	MR_print_locn = TRUE;
	#else
	    static const bool	MR_print_locn = FALSE;
	#endif

or

	#ifdef	MR_DEBUG_LVAL_REP
	    #define MR_print_locn TRUE
	#else
	    #define MR_print_locn FALSE
	#endif

Then the remaining `#ifdef' won't be needed -- GNU C will optimize out
the `if (MR_print_locn)' statements.  (The same applies for any good C
compiler, if you use `static const bool', or any merely half-decent C
compiler, if you use `#define').

This approach is better than conditional compilation, because the
code inside the `if' statements gets type-checked even when it is
not enabled.

> @@ -508,10 +574,16 @@
>  	*type_info = MR_create_type_info(type_params, pseudo_type_info);
>  
>  	if (i < MR_long_desc_var_count(label_layout)) {
> +#ifdef	MR_DEBUG_LVAL_REP
> +		printf("looking up long lval\n");
> +#endif
>  		*value = MR_lookup_long_lval_base(
>  			MR_long_desc_var_locn(label_layout, i),
>  			saved_regs, base_sp, base_curfr, &succeeded);
>  	} else {
> +#ifdef	MR_DEBUG_LVAL_REP
> +		printf("looking up short lval\n");
> +#endif

The code here, which use #ifdef alone, is inconsistent with the approach
take in earlier code, which combines #ifdef and if.

> Index: runtime/mercury_stack_layout.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
> retrieving revision 1.52
> diff -u -b -r1.52 mercury_stack_layout.h
> --- runtime/mercury_stack_layout.h	2001/06/02 09:35:03	1.52
> +++ runtime/mercury_stack_layout.h	2001/12/07 07:02:26
> @@ -373,7 +373,8 @@
>  		(&MR_long_desc_var_locn((sll), MR_long_desc_var_count(sll)))
>  #define	MR_short_desc_var_locn(sll, i)					    \
>  		(((MR_uint_least8_t *)					    \
> -			MR_end_of_long_desc_var_locns(sll))[(i)])
> +			MR_end_of_long_desc_var_locns(sll))		    \
> +		 		[(i - MR_long_desc_var_count(sll))])

`i' should be in parentheses here.
That last line should be

		 		[(i) - MR_long_desc_var_count(sll)])

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list