This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[RFC] fix char* restrict
- From: Dan Nicolaescu <dann at godzilla dot ICS dot UCI dot EDU>
- To: gcc at gcc dot gnu dot org
- Cc: Zack Weinberg <zack at codesourcery dot com>
- Date: Sun, 12 May 2002 16:23:32 -0700
- Subject: [RFC] fix char* restrict
As can be seen in the message archived at:
http://gcc.gnu.rg/ml/gcc-patches/2002-03/msg00274.html
char *restrict does not work as expected, restricted char*s are put in
alias set 0.
Why? alias.c:get_alias_set calls c-common.c:c_common_get_alias_set
that returns zero for a char*. get_alias_set sees the zero and
returns without checking if the "char*" is a "char* restrict". That
check would have occurred later in the code.
One way to fix make char* restrict is to somehow make language
specific lang_hooks.get_alias_set function signal that even though the
value it returns is 0 the processing in alias.c:get_alias_set should
continue to check for restricted pointers. This can be done by adding
another parameter to lang_hooks.get_alias_set.
Does anybody see a better solution?
A proposed patch follows. If it is acceptable I will submit it
properly. Right now I just want to make sure I am on the right track.
Thanks.
--dan
2002-05-12 Dan Nicolaescu <dann@ics.uci.edu>
* c-common.c (c_common_get_alias_set): Add extra parameter. Set it
in for a char*.
* alias.c (get_alias_set): Don't return for a restrict candidate.
*** alias.c.~1.170.~ Sat May 11 12:47:36 2002
--- alias.c Sun May 12 15:36:17 2002
***************
*** 470,479 ****
/* Remove any nops, then give the language a chance to do
something with this tree before we look at it. */
STRIP_NOPS (t);
! set = (*lang_hooks.get_alias_set) (t);
! if (set != -1)
! return set;
!
/* First see if the actual object referenced is an INDIRECT_REF from a
restrict-qualified pointer or a "void *". Replace
PLACEHOLDER_EXPRs. */
--- 470,482 ----
/* Remove any nops, then give the language a chance to do
something with this tree before we look at it. */
STRIP_NOPS (t);
! {
! int restrict_candidate_p = 0;
! set = (*lang_hooks.get_alias_set) (t, &restrict_candidate_p);
! if (set != -1 && (set == 0 && !restrict_candidate_p))
! return set;
! }
!
/* First see if the actual object referenced is an INDIRECT_REF from a
restrict-qualified pointer or a "void *". Replace
PLACEHOLDER_EXPRs. */
*** c-common.c.~1.320.~ Sat May 11 12:47:37 2002
--- c-common.c Sun May 12 16:10:39 2002
***************
*** 2484,2494 ****
}
/* Return the typed-based alias set for T, which may be an expression
! or a type. Return -1 if we don't do anything special. */
HOST_WIDE_INT
! c_common_get_alias_set (t)
tree t;
{
tree u;
--- 2484,2497 ----
}
/* Return the typed-based alias set for T, which may be an expression
! or a type. Return -1 if we don't do anything special.
! Set RESTRICT_CANDIDATE_P in case T should be checked if it's a
! restricted char pointer. */
HOST_WIDE_INT
! c_common_get_alias_set (t, restrict_candidate_p)
tree t;
+ int *restrict_candidate_p;
{
tree u;
***************
*** 2514,2520 ****
if (TREE_CODE_CLASS (TREE_CODE (t)) == 'r'
&& TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
&& TYPE_PRECISION (TREE_TYPE (t)) == TYPE_PRECISION (char_type_node))
! return 0;
/* That's all the expressions we handle specially. */
if (! TYPE_P (t))
--- 2517,2526 ----
if (TREE_CODE_CLASS (TREE_CODE (t)) == 'r'
&& TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
&& TYPE_PRECISION (TREE_TYPE (t)) == TYPE_PRECISION (char_type_node))
! {
! *restrict_candidate_p = 1;
! return 0;
! }
/* That's all the expressions we handle specially. */
if (! TYPE_P (t))