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]

PATCH: remove cv quals for alias analysis


For the purpose of alias analysis, const and volatile qualifiers are
sometimes considered to denote types in different alias sets.

This is correct (at least for C) but is rather pedantic.  Consider
this code:

  int i = 0xBEEF;
  int *pi = &i;
  int **ppi = π
  const int* const* const* pppi = &ppi;
  foo (***pppi);

At present, ***pppi and i are in different alias sets, so the store to
i can be moved after the load from ***pppi.  gcc warns about the
assignment to pppi, but g++ does not because this is legal C++.
Instead we silently generate bad code.

Note that if there were two levels of dereferncing here we would be
ok: the compiler already does the right thing.

I think we should ignore all cv quals when choosing alias sets, no
matter how deep in the type chain.

However, I'm not sure about restricted pointers.  Do I need to do more
in order not to break restrict quals?

Andrew.

2000-11-13  Andrew Haley  <aph@redhat.com>

	* tree.c (build_type_no_quals): New function.
	* tree.h (build_type_no_quals): Declare.
	* c-common.c (c_get_alias_set): When considering type
	compatibility for pointer types, ignore cv-qualifiers anywhere in
	a pointer chain.

Index: tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.c,v
retrieving revision 1.169
diff -p -2 -c -r1.169 tree.c
*** tree.c	2000/11/07 07:40:37	1.169
--- tree.c	2000/11/14 14:21:04
*************** build_reference_type (to_type)
*** 3799,3802 ****
--- 3799,3822 ----
  }
  
+ /* Build a type that is compatible with t but has no cv quals anywhere
+    in its type, thus
+ 
+    const char *const *const *  ->  char ***.  */
+ 
+ tree
+ build_type_no_quals (t)
+   tree t;
+ {
+   switch (TREE_CODE (t))
+     {
+     case POINTER_TYPE:
+       return build_pointer_type (build_type_no_quals (TREE_TYPE (t)));
+     case REFERENCE_TYPE:
+       return build_reference_type (build_type_no_quals (TREE_TYPE (t)));
+     default:
+       return TYPE_MAIN_VARIANT (t);
+     }
+ }
+ 
  /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
     MAXVAL should be the maximum value in the domain
Index: tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.h,v
retrieving revision 1.209
diff -p -2 -c -r1.209 tree.h
*** tree.h	2000/11/03 14:04:43	1.209
--- tree.h	2000/11/14 14:21:05
*************** extern void fixup_unsigned_type		PARAMS 
*** 1924,1927 ****
--- 1924,1928 ----
  extern tree build_pointer_type		PARAMS ((tree));
  extern tree build_reference_type 	PARAMS ((tree));
+ extern tree build_type_no_quals 	PARAMS ((tree));
  extern tree build_index_type		PARAMS ((tree));
  extern tree build_index_2_type		PARAMS ((tree, tree));
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.c,v
retrieving revision 1.188
diff -p -2 -c -r1.188 c-common.c
*** c-common.c	2000/11/13 14:14:41	1.188
--- c-common.c	2000/11/14 14:21:07
*************** lang_get_alias_set (t)
*** 4795,4801 ****
  	 the pointed-to types.  This issue has been reported to the
  	 C++ committee.  */
!       t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t));
!       t1 = ((TREE_CODE (t) == POINTER_TYPE)
! 	   ? build_pointer_type (t1) : build_reference_type (t1));
        if (t1 != t)
  	return get_alias_set (t1);
--- 4795,4799 ----
  	 the pointed-to types.  This issue has been reported to the
  	 C++ committee.  */
!       t1 = build_type_no_quals (t);
        if (t1 != t)
  	return get_alias_set (t1);
Index: tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.c,v
retrieving revision 1.169
diff -p -2 -c -r1.169 tree.c
*** tree.c	2000/11/07 07:40:37	1.169
--- tree.c	2000/11/14 14:38:39
*************** build_reference_type (to_type)
*** 3799,3802 ****
--- 3799,3822 ----
  }
  
+ /* Build a type that is compatible with t but has no cv quals anywhere
+    in its type, thus
+ 
+    const char *const *const *  ->  char ***.  */
+ 
+ tree
+ build_type_no_quals (t)
+   tree t;
+ {
+   switch (TREE_CODE (t))
+     {
+     case POINTER_TYPE:
+       return build_pointer_type (build_type_no_quals (TREE_TYPE (t)));
+     case REFERENCE_TYPE:
+       return build_reference_type (build_type_no_quals (TREE_TYPE (t)));
+     default:
+       return TYPE_MAIN_VARIANT (t);
+     }
+ }
+ 
  /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
     MAXVAL should be the maximum value in the domain
Index: tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.h,v
retrieving revision 1.209
diff -p -2 -c -r1.209 tree.h
*** tree.h	2000/11/03 14:04:43	1.209
--- tree.h	2000/11/14 14:38:40
*************** extern void fixup_unsigned_type		PARAMS 
*** 1924,1927 ****
--- 1924,1928 ----
  extern tree build_pointer_type		PARAMS ((tree));
  extern tree build_reference_type 	PARAMS ((tree));
+ extern tree build_type_no_quals 	PARAMS ((tree));
  extern tree build_index_type		PARAMS ((tree));
  extern tree build_index_2_type		PARAMS ((tree, tree));
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.c,v
retrieving revision 1.188
diff -p -2 -c -r1.188 c-common.c
*** c-common.c	2000/11/13 14:14:41	1.188
--- c-common.c	2000/11/14 14:38:42
*************** lang_get_alias_set (t)
*** 4795,4801 ****
  	 the pointed-to types.  This issue has been reported to the
  	 C++ committee.  */
!       t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t));
!       t1 = ((TREE_CODE (t) == POINTER_TYPE)
! 	   ? build_pointer_type (t1) : build_reference_type (t1));
        if (t1 != t)
  	return get_alias_set (t1);
--- 4795,4799 ----
  	 the pointed-to types.  This issue has been reported to the
  	 C++ committee.  */
!       t1 = build_type_no_quals (t);
        if (t1 != t)
  	return get_alias_set (t1);

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