__builtin_constant_p problem [was Re: egcs-19990103 on ...]

Edward Jason Riedy ejr@cs.berkeley.edu
Tue Jan 5 22:53:00 GMT 1999


And Horst von Brand writes:
 - linux-2.2.0-pre4, glibc-2.0.108, binutils-2.9.1.0.19a

 - ../../egcs-19990103/gcc/expr.c:2663: Internal compiler error in function emi
 + t_move_insn_1

It seems to dislike the strncpy definition in /usr/include/bits/string2.h.  
The important part of the definition selected on my machine is:
> #  define strncpy(dest, src, n) \
>   (__extension__ (__builtin_constant_p (src) && __builtin_constant_p (n)    \

expand_builtin is trying to convert the SImode __builtin_constant_p
to the requested VOIDmode.  That triggers a convert_move, which is
none too happy about the VOIDmode destination and aborts.

Two possible fixes are to return the rtx in either VOIDmode or
ptr_mode when VOIDmode is requested.  The former causes other 
problems I don't understand (an internal error in do_jump), but 
it feels more correct.  The included patch takes the latter route.
I don't have the testing harness set up at home, but it bootstraps
the gcc dir with it...

Jason, #define abort(x) do { } while (1)

ChangeLog:

	* expr.c (expand_builtin): In case BUILT_IN_CONSTANT_P, return
	a ptr_mode instruction when the requested mode is VOIDmode.

--- expr.c.orig	Tue Jan  5 22:00:03 1999
+++ expr.c	Tue Jan  5 22:01:43 1999
@@ -9026,11 +9026,13 @@
 	     get a chance to see if it can deduce whether ARG is constant.  */
 	  /* ??? We always generate the CONST in ptr_mode since that's
 	     certain to be valid on this machine, then convert it to
-	     whatever we need.  */
+	     whatever we need.	However, the requested mode may be
+	     VOIDmode, in which case we don't bother.  */
 
 	  tmp = expand_expr (arg, NULL_RTX, VOIDmode, 0);
 	  tmp = gen_rtx_CONSTANT_P_RTX (ptr_mode, tmp);
 	  tmp = gen_rtx_CONST (ptr_mode, tmp);
+	  if (VOIDmode != mode)
 	  tmp = convert_to_mode (mode, tmp, 0);
 	  return tmp;
 	}



More information about the Gcc-bugs mailing list