This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Secure scan for multiple back edges in loop_iterations



Context:
--------

This follows up from the short thread headed at

  http://gcc.gnu.org/ml/gcc/2001-11/msg01355.html

The basic context is :

     Trying to bootstrap Ada on hppa1.1-hp-hpux11.00 with our internal GNAT
     tree leads to SEGV from within loop_iterations. Basically, we get to

      /* If there are multiple conditionalized loop exit tests, they may jump
          back to differing CODE_LABELs.  */
       if (loop->top && loop->cont)
         {
           rtx temp = PREV_INSN (last_loop_insn);

           do
             {
               if (GET_CODE (temp) == JUMP_INSN
                   /* Previous unrolling may have generated new insns ...
                      by the uid_luid array.  */
                   && INSN_UID (JUMP_LABEL (temp)) < max_uid_for_loop

      with a temp looking like the following :

      (jump_insn 5407 5406 5408 (addr_vec:DI[ 
                 (label_ref:SI 5389)
                 ...

      GET_CODE (temp) is indeed JUMP_INSN, but the associated JUMP_LABEL is
      NULL and INSN_UID dereferences it.

This has been observed while compiling sem_attr.adb with the stage1 compiler
using a 20011129 GCC source base.

The patch below is a suggestion to fix this problem.

Kind Regards,

Olivier

ChangeLog:
----------

2001-11-30  Olivier Hainque <hainque@act-europe.fr>

	* unroll.c (loop_iterations): Give up on jumps with null JUMP_LABEL
        while scanning for multiple back edges.

Testing:
--------

Check that the compilation of the initial Ada file now completes successfully
on hppa1.1-hp-hpux11.00.

Bootstrap and regression tests successful for c, c++ on
i686-pc-linux-gnu. Tried java, but make dies even without the patch :

.../src/libjava/jni.cc: In function `T 
   _Jv_JNI_CallAnyMethodV(JNIEnv*, java::lang::Object*, java::lang::Class*, 
   _Jv_Method*, char*) [with T = jfloat, invocation_type style = nonvirtual]':
.../src/libjava/jni.cc:2600:   instantiated from here
.../src/libjava/jni.cc:772: Internal compiler error in 
   compensate_edge, at reg-stack.c:2564

Patch:
------

*** unroll.c	2001/11/27 22:09:09	1.149
--- unroll.c	2001/11/30 08:51:29
*************** loop_iterations (loop)
*** 3528,3545 ****
  
        do
  	{
! 	  if (GET_CODE (temp) == JUMP_INSN
! 	      /* Previous unrolling may have generated new insns not covered
! 		 by the uid_luid array.  */
! 	      && INSN_UID (JUMP_LABEL (temp)) < max_uid_for_loop
! 	      /* Check if we jump back into the loop body.  */
! 	      && INSN_LUID (JUMP_LABEL (temp)) > INSN_LUID (loop->top)
! 	      && INSN_LUID (JUMP_LABEL (temp)) < INSN_LUID (loop->cont))
  	    {
! 	      if (loop_dump_stream)
! 		fprintf (loop_dump_stream,
! 			 "Loop iterations: Loop has multiple back edges.\n");
! 	      return 0;
  	    }
  	}
        while ((temp = PREV_INSN (temp)) != loop->cont);
--- 3528,3558 ----
  
        do
  	{
! 	  if (GET_CODE (temp) == JUMP_INSN)
  	    {
! 	      /* There are some kinds of jumps we can't deal with easily.  */
! 	      if (JUMP_LABEL (temp) == 0)
! 		{
! 		  if (loop_dump_stream)
! 		    fprintf
! 		      (loop_dump_stream,
! 		       "Loop iterations: Jump insn has null JUMP_LABEL.\n");
! 		  return 0;
! 		}
! 
! 	      if (/* Previous unrolling may have generated new insns not
! 		     covered by the uid_luid array.  */
! 		  INSN_UID (JUMP_LABEL (temp)) < max_uid_for_loop
! 		  /* Check if we jump back into the loop body.  */
! 		  && INSN_LUID (JUMP_LABEL (temp)) > INSN_LUID (loop->top)
! 		  && INSN_LUID (JUMP_LABEL (temp)) < INSN_LUID (loop->cont))
! 		{
! 		  if (loop_dump_stream)
! 		    fprintf 
! 		      (loop_dump_stream,
! 		       "Loop iterations: Loop has multiple back edges.\n");
! 		  return 0;
! 		}
  	    }
  	}
        while ((temp = PREV_INSN (temp)) != loop->cont);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]