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]

Re: PATCH to implement `restrict' in C



I don't have much time for gcc work now; here are my latest restrict
patches:

*** c-decl.c.egcs	Wed Feb 18 18:10:08 1998
--- c-decl.c	Sun Mar  1 16:39:18 1998
***************
*** 4243,4248 ****
--- 4243,4249 ----
    int longlong = 0;
    int constp;
    int volatilep;
+   int restrictp;
    int inlinep;
    int explicit_int = 0;
    int explicit_char = 0;
***************
*** 4555,4560 ****
--- 4556,4562 ----
  
    constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
    volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
+   restrictp = !! (specbits & 1 << (int) RID_RESTRICT);
    inlinep = !! (specbits & (1 << (int) RID_INLINE));
    if (constp > 1)
      pedwarn ("duplicate `const'");
***************
*** 4870,4877 ****
--- 4872,4883 ----
  	     does not make the function foo const.  */
  	  if (constp || volatilep)
  	    type = c_build_type_variant (type, constp, volatilep);
+ 	  if (restrictp)
+ 	    error ("`restrict' applied to non-pointer");
+ 	  
  	  constp = 0;
  	  volatilep = 0;
+ 	  restrictp = 0;
  
  	  type = build_function_type (type, arg_types);
  	  declarator = TREE_OPERAND (declarator, 0);
***************
*** 4897,4906 ****
--- 4903,4918 ----
  	  if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
  	      && (constp || volatilep))
  	    pedwarn ("ANSI C forbids const or volatile function types");
+ 	  else if (restrictp
+ 		   && TREE_CODE (type) != ERROR_MARK
+ 		   && TREE_CODE (type) != POINTER_TYPE)
+ 	    error ("`restrict' applied to non-pointer");
+ 
  	  if (constp || volatilep)
  	    type = c_build_type_variant (type, constp, volatilep);
  	  constp = 0;
  	  volatilep = 0;
+ 	  restrictp = 0;
  	  size_varies = 0;
  
  	  type = build_pointer_type (type);
***************
*** 4919,4924 ****
--- 4931,4938 ----
  		    constp++;
  		  else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  		    volatilep++;
+ 		  else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_RESTRICT])
+ 		    restrictp++;
  		  else if (!erred)
  		    {
  		      erred = 1;
***************
*** 4929,4934 ****
--- 4943,4950 ----
  		pedwarn ("duplicate `const'");
  	      if (volatilep > 1)
  		pedwarn ("duplicate `volatile'");
+ 	      if (restrictp > 1)
+ 		pedwarn ("duplicate `restrict'");
  	    }
  
  	  declarator = TREE_OPERAND (declarator, 0);
***************
*** 4955,4962 ****
        /* Note that the grammar rejects storage classes
  	 in typenames, fields or parameters */
        if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
! 	  && (constp || volatilep))
! 	pedwarn ("ANSI C forbids const or volatile function types");
        if (constp || volatilep)
  	type = c_build_type_variant (type, constp, volatilep);
        decl = build_decl (TYPE_DECL, declarator, type);
--- 4971,4978 ----
        /* Note that the grammar rejects storage classes
  	 in typenames, fields or parameters */
        if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
! 	  && (constp || volatilep || restrictp))
! 	pedwarn ("ANSI C forbids const, volatile, or restrict function types");
        if (constp || volatilep)
  	type = c_build_type_variant (type, constp, volatilep);
        decl = build_decl (TYPE_DECL, declarator, type);
***************
*** 4990,4997 ****
        /* Note that the grammar rejects storage classes
  	 in typenames, fields or parameters */
        if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
! 	  && (constp || volatilep))
! 	pedwarn ("ANSI C forbids const or volatile function types");
        if (constp || volatilep)
  	type = c_build_type_variant (type, constp, volatilep);
        pop_obstacks ();
--- 5006,5013 ----
        /* Note that the grammar rejects storage classes
  	 in typenames, fields or parameters */
        if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
! 	  && (constp || volatilep || restrictp))
! 	pedwarn ("ANSI C forbids const, volatile, or restrict function types");
        if (constp || volatilep)
  	type = c_build_type_variant (type, constp, volatilep);
        pop_obstacks ();
***************
*** 5036,5042 ****
  	    if (constp || volatilep)
  	      type = c_build_type_variant (type, constp, volatilep);
  	    type = build_pointer_type (type);
! 	    volatilep = constp = 0;
  	    size_varies = 0;
  	  }
  	else if (TREE_CODE (type) == FUNCTION_TYPE)
--- 5052,5058 ----
  	    if (constp || volatilep)
  	      type = c_build_type_variant (type, constp, volatilep);
  	    type = build_pointer_type (type);
! 	    volatilep = constp = restrictp = 0;
  	    size_varies = 0;
  	  }
  	else if (TREE_CODE (type) == FUNCTION_TYPE)
***************
*** 5046,5052 ****
  	    if (constp || volatilep)
  	      type = c_build_type_variant (type, constp, volatilep);
  	    type = build_pointer_type (type);
! 	    volatilep = constp = 0;
  	  }
  
  	decl = build_decl (PARM_DECL, declarator, type);
--- 5062,5068 ----
  	    if (constp || volatilep)
  	      type = c_build_type_variant (type, constp, volatilep);
  	    type = build_pointer_type (type);
! 	    volatilep = constp = restrictp = 0;
  	  }
  
  	decl = build_decl (PARM_DECL, declarator, type);
***************
*** 5154,5159 ****
--- 5170,5178 ----
  	    && TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
  	  warning ("`noreturn' function returns non-void value");
  
+ 	if (restrictp)
+ 	  error ("`restrict' applied to non-pointer");
+ 
  	if (extern_ref)
  	  DECL_EXTERNAL (decl) = 1;
  	/* Record absence of global scope for `static' or `auto'.  */
***************
*** 5246,5251 ****
--- 5265,5277 ----
  	TREE_SIDE_EFFECTS (decl) = 1;
  	TREE_THIS_VOLATILE (decl) = 1;
        }
+     if (restrictp)
+       {
+ 	if (TREE_CODE (type) != POINTER_TYPE && TREE_CODE (type) != ERROR_MARK)
+ 	  error ("`restrict' applied to non-pointer");
+ 	else
+ 	  DECL_RESTRICT (decl) = 1;
+       }
      /* If a type has volatile components, it should be stored in memory.
         Otherwise, the fact that those components are volatile
         will be ignored, and would even crash the compiler.  */
*** tree.h.egcs	Wed Feb 18 18:11:09 1998
--- tree.h	Fri Feb 20 19:39:22 1998
***************
***************
*** 1093,1098 ****
--- 1094,1102 ----
  /* Used to indicate that this DECL represents a compiler-generated entity.  */
  #define DECL_ARTIFICIAL(NODE) ((NODE)->decl.artificial_flag)
  
+ /* In a VAR_DECL or PARM_DECL, nonzero if this is a restricted pointer.  */
+ #define DECL_RESTRICT(NODE) (NODE)->decl.static_ctor_flag
+ 
  /* Used to indicate that this DECL has weak linkage.  */
  #define DECL_WEAK(NODE) ((NODE)->decl.weak_flag)
  
*** c-lex.h.egcs	Mon Aug 11 11:57:03 1997
--- c-lex.h	Sat Jan  3 22:50:02 1998
***************
*** 42,48 ****
    RID_CONST,
    RID_VOLATILE,
    RID_INLINE,
!   RID_NOALIAS,
    RID_ITERATOR,
    RID_COMPLEX,
  
--- 42,48 ----
    RID_CONST,
    RID_VOLATILE,
    RID_INLINE,
!   RID_RESTRICT,
    RID_ITERATOR,
    RID_COMPLEX,
  
*** c-lex.c.egcs	Wed Jan 28 18:25:08 1998
--- c-lex.c	Fri Jan 30 19:17:47 1998
***************
*** 257,262 ****
--- 257,263 ----
    ridpointers[(int) RID_INLINE] = get_identifier ("inline");
    ridpointers[(int) RID_CONST] = get_identifier ("const");
    ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
+   ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
    ridpointers[(int) RID_AUTO] = get_identifier ("auto");
    ridpointers[(int) RID_STATIC] = get_identifier ("static");
    ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
***************
*** 290,295 ****
--- 291,297 ----
        UNSET_RESERVED_WORD ("inline");
        UNSET_RESERVED_WORD ("iterator");
        UNSET_RESERVED_WORD ("complex");
+       UNSET_RESERVED_WORD ("restrict");
      }
    if (flag_no_asm)
      {
***************
*** 298,303 ****
--- 300,306 ----
        UNSET_RESERVED_WORD ("inline");
        UNSET_RESERVED_WORD ("iterator");
        UNSET_RESERVED_WORD ("complex");
+       UNSET_RESERVED_WORD ("restrict"); /* C9X but not C89 */
      }
  }
  
*** function.c.egcs	Sat Feb 28 16:51:33 1998
--- function.c	Sun Mar  1 16:38:34 1998
***************
*** 4082,4088 ****
  	      end_sequence ();
  	    }
  	  else
! 	    emit_move_insn (parmreg, validize_mem (entry_parm));
  
  	  /* If we were passed a pointer but the actual value
  	     can safely live in a register, put it in one.  */
--- 4082,4097 ----
  	      end_sequence ();
  	    }
  	  else
! 	    {
! 	      emit_move_insn (parmreg, validize_mem (entry_parm));
! 	      if (DECL_RESTRICT (parm))
! 		{
! 		  rtx last = get_last_insn ();
! 		  REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_NOALIAS,
! 							parmreg,
! 							REG_NOTES (last));
! 		}
! 	    }
  
  	  /* If we were passed a pointer but the actual value
  	     can safely live in a register, put it in one.  */
*** c-parse.gperf.egcs	Mon Aug 11 11:57:03 1997
--- c-parse.gperf	Sun Jan  4 12:03:35 1998
***************
*** 35,40 ****
--- 35,41 ----
  __label__, LABEL, NORID
  __real, REALPART, NORID
  __real__, REALPART, NORID
+ _Restrict, TYPE_QUAL, RID_RESTRICT
  __signed, TYPESPEC, RID_SIGNED
  __signed__, TYPESPEC, RID_SIGNED
  __typeof, TYPEOF, NORID
***************
*** 68,73 ****
--- 69,75 ----
  oneway, TYPE_QUAL, RID_ONEWAY
  out, TYPE_QUAL, RID_OUT
  register, SCSPEC, RID_REGISTER
+ restrict, TYPE_QUAL, RID_RESTRICT
  return, RETURN, NORID
  short, TYPESPEC, RID_SHORT
  signed, TYPESPEC, RID_SIGNED


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