public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH INSTALLED]: const typedefs part 1/N
@ 2007-07-25 18:14 Kaveh R. GHAZI
  2007-08-02  0:14 ` Andrew Pinski
  0 siblings, 1 reply; 8+ messages in thread
From: Kaveh R. GHAZI @ 2007-07-25 18:14 UTC (permalink / raw)
  To: gcc-patches

The patch below (and several upcoming ones) implement the core of the
const typedefs project I proposed last year:
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00383.html

This patch and the constification (constipation?) followups were
pre-approved by Mark for stage2 here:
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00415.html

Some of the benefits of this change are noted here:
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00389.html

While I didn't necessarily expect any optimization improvements, I was
pleasantly surprised to find that when all my current patches are applied
a checking-enabled cc1 was 1.3% faster compiling combine.i. However the
checking-disabled cc1 showed little or no difference.

I also managed to get the -Wcast-qual warnings down from ~375 to ~35. My
hope is that we can get it low enough to include that flag in the
bootstrap process.  There are some problematic cases, but I have ideas on
how to address them which I will get into later.

I've updated the patches for the current sources and rebootstrapped on
sparc-sun-solaris2.10, no regressions.  I also built the compiler with
--enable-checking=yes,rtl to test the rtl macros below and make sure I
didn't typo anything.

Part 1 installed on mainline.

		--Kaveh


2006-07-25  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* coretypes.h (const_bitmap, const_rtx, const_rtvec, const_tree):
	New.

	* rtl.h (RTL_CHECK1, RTL_CHECK2, RTL_CHECKC1, RTL_CHECKC2,
	RTVEC_ELT, XWINT, XCWINT, XCMWINT, XCNMPRV, BLOCK_SYMBOL_CHECK,
	RTL_FLAG_CHECK1, RTL_FLAG_CHECK2, RTL_FLAG_CHECK3,
	RTL_FLAG_CHECK4, RTL_FLAG_CHECK5, RTL_FLAG_CHECK6,
	RTL_FLAG_CHECK7, RTL_FLAG_CHECK8, LABEL_KIND, SET_LABEL_KIND):
	Preserve const-ness of parameters through use of __typeof(),
	also constify and tidy.

	* tree.h (TREE_CHECK, TREE_NOT_CHECK, TREE_CHECK2,
	TREE_NOT_CHECK2, TREE_CHECK3, TREE_NOT_CHECK3, TREE_CHECK4,
	NON_TREE_CHECK4, TREE_CHECK5, TREE_NOT_CHECK5,
	CONTAINS_STRUCT_CHECK, TREE_CLASS_CHECK, TREE_RANGE_CHECK,
	OMP_CLAUSE_SUBCODE_CHECK, OMP_CLAUSE_RANGE_CHECK, EXPR_CHECK,
	GIMPLE_STMT_CHECK, NON_TYPE_CHECK, TREE_VEC_ELT_CHECK,
	PHI_NODE_ELT_CHECK, OMP_CLAUSE_ELT_CHECK, TREE_OPERAND_CHECK,
	TREE_OPERAND_CHECK_CODE, GIMPLE_STMT_OPERAND_CHECK,
	TREE_RTL_OPERAND_CHECK, TREE_CHAIN, TREE_TYPE): Likewise.

diff -rup orig/egcc-SVN20070721/gcc/coretypes.h egcc-SVN20070721/gcc/coretypes.h
--- orig/egcc-SVN20070721/gcc/coretypes.h	2006-11-03 20:01:55.000000000 -0500
+++ egcc-SVN20070721/gcc/coretypes.h	2007-07-22 12:26:35.278794646 -0400
@@ -39,12 +39,16 @@ Software Foundation, 51 Franklin Street,

 struct bitmap_head_def;
 typedef struct bitmap_head_def *bitmap;
+typedef const struct bitmap_head_def *const_bitmap;
 struct rtx_def;
 typedef struct rtx_def *rtx;
+typedef const struct rtx_def *const_rtx;
 struct rtvec_def;
 typedef struct rtvec_def *rtvec;
+typedef const struct rtvec_def *const_rtvec;
 union tree_node;
 typedef union tree_node *tree;
+typedef const union tree_node *const_tree;
 union section;
 typedef union section section;

@@ -78,8 +82,11 @@ struct _dont_use_rtx_here_;
 struct _dont_use_rtvec_here_;
 union _dont_use_tree_here_;
 #define rtx struct _dont_use_rtx_here_ *
+#define const_rtx struct _dont_use_rtx_here_ *
 #define rtvec struct _dont_use_rtvec_here *
+#define const_rtvec struct _dont_use_rtvec_here *
 #define tree union _dont_use_tree_here_ *
+#define const_tree union _dont_use_tree_here_ *

 #endif

diff -rup orig/egcc-SVN20070721/gcc/rtl.h egcc-SVN20070721/gcc/rtl.h
--- orig/egcc-SVN20070721/gcc/rtl.h	2007-07-13 23:02:14.000000000 -0400
+++ egcc-SVN20070721/gcc/rtl.h	2007-07-22 12:26:35.287606744 -0400
@@ -454,7 +454,7 @@ struct rtvec_def GTY(()) {
 /* The bit with a star outside the statement expr and an & inside is
    so that N can be evaluated only once.  */
 #define RTL_CHECK1(RTX, N, C1) __extension__				\
-(*({ rtx const _rtx = (RTX); const int _n = (N);			\
+(*({ __typeof (RTX) const _rtx = (RTX); const int _n = (N);		\
      const enum rtx_code _code = GET_CODE (_rtx);			\
      if (_n < 0 || _n >= GET_RTX_LENGTH (_code))			\
        rtl_check_failed_bounds (_rtx, _n, __FILE__, __LINE__,		\
@@ -465,7 +465,7 @@ struct rtvec_def GTY(()) {
      &_rtx->u.fld[_n]; }))

 #define RTL_CHECK2(RTX, N, C1, C2) __extension__			\
-(*({ rtx const _rtx = (RTX); const int _n = (N);			\
+(*({ __typeof (RTX) const _rtx = (RTX); const int _n = (N);		\
      const enum rtx_code _code = GET_CODE (_rtx);			\
      if (_n < 0 || _n >= GET_RTX_LENGTH (_code))			\
        rtl_check_failed_bounds (_rtx, _n, __FILE__, __LINE__,		\
@@ -477,14 +477,14 @@ struct rtvec_def GTY(()) {
      &_rtx->u.fld[_n]; }))

 #define RTL_CHECKC1(RTX, N, C) __extension__				\
-(*({ rtx const _rtx = (RTX); const int _n = (N);			\
+(*({ __typeof (RTX) const _rtx = (RTX); const int _n = (N);		\
      if (GET_CODE (_rtx) != (C))					\
        rtl_check_failed_code1 (_rtx, (C), __FILE__, __LINE__,		\
 			       __FUNCTION__);				\
      &_rtx->u.fld[_n]; }))

 #define RTL_CHECKC2(RTX, N, C1, C2) __extension__			\
-(*({ rtx const _rtx = (RTX); const int _n = (N);			\
+(*({ __typeof (RTX) const _rtx = (RTX); const int _n = (N);		\
      const enum rtx_code _code = GET_CODE (_rtx);			\
      if (_code != (C1) && _code != (C2))				\
        rtl_check_failed_code2 (_rtx, (C1), (C2), __FILE__, __LINE__,	\
@@ -492,14 +492,14 @@ struct rtvec_def GTY(()) {
      &_rtx->u.fld[_n]; }))

 #define RTVEC_ELT(RTVEC, I) __extension__				\
-(*({ rtvec const _rtvec = (RTVEC); const int _i = (I);			\
+(*({ __typeof (RTVEC) const _rtvec = (RTVEC); const int _i = (I);	\
      if (_i < 0 || _i >= GET_NUM_ELEM (_rtvec))				\
        rtvec_check_failed_bounds (_rtvec, _i, __FILE__, __LINE__,	\
 				  __FUNCTION__);			\
      &_rtvec->elem[_i]; }))

 #define XWINT(RTX, N) __extension__					\
-(*({ rtx const _rtx = (RTX); const int _n = (N);			\
+(*({ __typeof (RTX) const _rtx = (RTX); const int _n = (N);		\
      const enum rtx_code _code = GET_CODE (_rtx);			\
      if (_n < 0 || _n >= GET_RTX_LENGTH (_code))			\
        rtl_check_failed_bounds (_rtx, _n, __FILE__, __LINE__,		\
@@ -510,29 +510,29 @@ struct rtvec_def GTY(()) {
      &_rtx->u.hwint[_n]; }))

 #define XCWINT(RTX, N, C) __extension__					\
-(*({ rtx const _rtx = (RTX);						\
+(*({ __typeof (RTX) const _rtx = (RTX);					\
      if (GET_CODE (_rtx) != (C))					\
        rtl_check_failed_code1 (_rtx, (C), __FILE__, __LINE__,		\
 			       __FUNCTION__);				\
      &_rtx->u.hwint[N]; }))

 #define XCMWINT(RTX, N, C, M) __extension__				\
-(*({ rtx const _rtx = (RTX);						\
+(*({ __typeof (RTX) const _rtx = (RTX);					\
      if (GET_CODE (_rtx) != (C) || GET_MODE (_rtx) != (M))		\
        rtl_check_failed_code_mode (_rtx, (C), (M), false, __FILE__,	\
 				   __LINE__, __FUNCTION__);		\
      &_rtx->u.hwint[N]; }))

 #define XCNMPRV(RTX, C, M) __extension__				\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE (_rtx) != (C) || GET_MODE (_rtx) == (M))		\
      rtl_check_failed_code_mode (_rtx, (C), (M), true, __FILE__,	\
 				 __LINE__, __FUNCTION__);		\
    &_rtx->u.rv; })

 #define BLOCK_SYMBOL_CHECK(RTX) __extension__				\
-({ rtx const _symbol = (RTX);						\
-   unsigned int flags = RTL_CHECKC1 (_symbol, 1, SYMBOL_REF).rt_int;	\
+({ __typeof (RTX) const _symbol = (RTX);				\
+   const unsigned int flags = RTL_CHECKC1 (_symbol, 1, SYMBOL_REF).rt_int; \
    if ((flags & SYMBOL_FLAG_HAS_BLOCK_INFO) == 0)			\
      rtl_check_failed_block_symbol (__FILE__, __LINE__,			\
 				    __FUNCTION__);			\
@@ -585,21 +585,21 @@ extern void rtvec_check_failed_bounds (r

 #if defined ENABLE_RTL_FLAG_CHECKING && (GCC_VERSION >= 2007)
 #define RTL_FLAG_CHECK1(NAME, RTX, C1) __extension__			\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1)						\
      rtl_check_failed_flag  (NAME, _rtx, __FILE__, __LINE__,		\
 			     __FUNCTION__);				\
    _rtx; })

 #define RTL_FLAG_CHECK2(NAME, RTX, C1, C2) __extension__		\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2)			\
      rtl_check_failed_flag  (NAME,_rtx, __FILE__, __LINE__,		\
 			      __FUNCTION__);				\
    _rtx; })

 #define RTL_FLAG_CHECK3(NAME, RTX, C1, C2, C3) __extension__		\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2			\
        && GET_CODE(_rtx) != C3)						\
      rtl_check_failed_flag  (NAME, _rtx, __FILE__, __LINE__,		\
@@ -607,7 +607,7 @@ extern void rtvec_check_failed_bounds (r
    _rtx; })

 #define RTL_FLAG_CHECK4(NAME, RTX, C1, C2, C3, C4) __extension__	\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2			\
        && GET_CODE(_rtx) != C3 && GET_CODE(_rtx) != C4)			\
      rtl_check_failed_flag  (NAME, _rtx, __FILE__, __LINE__,		\
@@ -615,7 +615,7 @@ extern void rtvec_check_failed_bounds (r
    _rtx; })

 #define RTL_FLAG_CHECK5(NAME, RTX, C1, C2, C3, C4, C5) __extension__	\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2			\
        && GET_CODE(_rtx) != C3 && GET_CODE(_rtx) != C4			\
        && GET_CODE(_rtx) != C5)						\
@@ -625,7 +625,7 @@ extern void rtvec_check_failed_bounds (r

 #define RTL_FLAG_CHECK6(NAME, RTX, C1, C2, C3, C4, C5, C6)		\
   __extension__								\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2			\
        && GET_CODE(_rtx) != C3 && GET_CODE(_rtx) != C4			\
        && GET_CODE(_rtx) != C5 && GET_CODE(_rtx) != C6)			\
@@ -635,7 +635,7 @@ extern void rtvec_check_failed_bounds (r

 #define RTL_FLAG_CHECK7(NAME, RTX, C1, C2, C3, C4, C5, C6, C7)		\
   __extension__								\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2			\
        && GET_CODE(_rtx) != C3 && GET_CODE(_rtx) != C4			\
        && GET_CODE(_rtx) != C5 && GET_CODE(_rtx) != C6			\
@@ -646,7 +646,7 @@ extern void rtvec_check_failed_bounds (r

 #define RTL_FLAG_CHECK8(NAME, RTX, C1, C2, C3, C4, C5, C6, C7, C8)	\
   __extension__								\
-({ rtx const _rtx = (RTX);						\
+({ __typeof (RTX) const _rtx = (RTX);					\
    if (GET_CODE(_rtx) != C1 && GET_CODE(_rtx) != C2			\
        && GET_CODE(_rtx) != C3 && GET_CODE(_rtx) != C4			\
        && GET_CODE(_rtx) != C5 && GET_CODE(_rtx) != C6			\
@@ -910,7 +910,7 @@ enum label_kind

 /* Retrieve the kind of LABEL.  */
 #define LABEL_KIND(LABEL) __extension__					\
-({ rtx const _label = (LABEL);						\
+({ __typeof (LABEL) const _label = (LABEL);					\
    if (GET_CODE (_label) != CODE_LABEL)					\
      rtl_check_failed_flag ("LABEL_KIND", _label, __FILE__, __LINE__,	\
 			    __FUNCTION__);				\
@@ -918,8 +918,8 @@ enum label_kind

 /* Set the kind of LABEL.  */
 #define SET_LABEL_KIND(LABEL, KIND) do {				\
-   rtx _label = (LABEL);						\
-   unsigned int _kind = (KIND);						\
+   rtx const _label = (LABEL);						\
+   const unsigned int _kind = (KIND);					\
    if (GET_CODE (_label) != CODE_LABEL)					\
      rtl_check_failed_flag ("SET_LABEL_KIND", _label, __FILE__, __LINE__, \
 			    __FUNCTION__);				\
@@ -935,8 +935,8 @@ enum label_kind

 /* Set the kind of LABEL.  */
 #define SET_LABEL_KIND(LABEL, KIND) do {				\
-   rtx _label = (LABEL);						\
-   unsigned int _kind = (KIND);						\
+   rtx const _label = (LABEL);						\
+   const unsigned int _kind = (KIND);					\
    _label->jump = ((_kind >> 1) & 1);					\
    _label->call = (_kind & 1);						\
 } while (0)
diff -rup orig/egcc-SVN20070721/gcc/tree.h egcc-SVN20070721/gcc/tree.h
--- orig/egcc-SVN20070721/gcc/tree.h	2007-07-13 12:23:45.000000000 -0400
+++ egcc-SVN20070721/gcc/tree.h	2007-07-22 12:29:34.480593318 -0400
@@ -601,21 +601,21 @@ enum tree_node_structure_enum {
 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)

 #define TREE_CHECK(T, CODE) __extension__				\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) != (CODE))					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__, 	\
 			 (CODE), 0);					\
     __t; })

 #define TREE_NOT_CHECK(T, CODE) __extension__				\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) == (CODE))					\
       tree_not_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,	\
 			     (CODE), 0);				\
     __t; })

 #define TREE_CHECK2(T, CODE1, CODE2) __extension__			\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) != (CODE1)					\
 	&& TREE_CODE (__t) != (CODE2))					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,		\
@@ -623,7 +623,7 @@ enum tree_node_structure_enum {
     __t; })

 #define TREE_NOT_CHECK2(T, CODE1, CODE2) __extension__			\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) == (CODE1)					\
 	|| TREE_CODE (__t) == (CODE2))					\
       tree_not_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,	\
@@ -631,7 +631,7 @@ enum tree_node_structure_enum {
     __t; })

 #define TREE_CHECK3(T, CODE1, CODE2, CODE3) __extension__		\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) != (CODE1)					\
 	&& TREE_CODE (__t) != (CODE2)					\
 	&& TREE_CODE (__t) != (CODE3))					\
@@ -640,7 +640,7 @@ enum tree_node_structure_enum {
     __t; })

 #define TREE_NOT_CHECK3(T, CODE1, CODE2, CODE3) __extension__		\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) == (CODE1)					\
 	|| TREE_CODE (__t) == (CODE2)					\
 	|| TREE_CODE (__t) == (CODE3))					\
@@ -649,7 +649,7 @@ enum tree_node_structure_enum {
     __t; })

 #define TREE_CHECK4(T, CODE1, CODE2, CODE3, CODE4) __extension__	\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) != (CODE1)					\
 	&& TREE_CODE (__t) != (CODE2)					\
 	&& TREE_CODE (__t) != (CODE3)					\
@@ -659,7 +659,7 @@ enum tree_node_structure_enum {
     __t; })

 #define NON_TREE_CHECK4(T, CODE1, CODE2, CODE3, CODE4) __extension__	\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) == (CODE1)					\
 	|| TREE_CODE (__t) == (CODE2)					\
 	|| TREE_CODE (__t) == (CODE3)					\
@@ -669,7 +669,7 @@ enum tree_node_structure_enum {
     __t; })

 #define TREE_CHECK5(T, CODE1, CODE2, CODE3, CODE4, CODE5) __extension__	\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) != (CODE1)					\
 	&& TREE_CODE (__t) != (CODE2)					\
 	&& TREE_CODE (__t) != (CODE3)					\
@@ -680,7 +680,7 @@ enum tree_node_structure_enum {
     __t; })

 #define TREE_NOT_CHECK5(T, CODE1, CODE2, CODE3, CODE4, CODE5) __extension__ \
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) == (CODE1)					\
 	|| TREE_CODE (__t) == (CODE2)					\
 	|| TREE_CODE (__t) == (CODE3)					\
@@ -691,28 +691,28 @@ enum tree_node_structure_enum {
     __t; })

 #define CONTAINS_STRUCT_CHECK(T, STRUCT) __extension__			\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
   if (tree_contains_struct[TREE_CODE(__t)][(STRUCT)] != 1)		\
       tree_contains_struct_check_failed (__t, (STRUCT), __FILE__, __LINE__,	\
 			       __FUNCTION__);				\
     __t; })

 #define TREE_CLASS_CHECK(T, CLASS) __extension__			\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE_CLASS (TREE_CODE(__t)) != (CLASS))			\
       tree_class_check_failed (__t, (CLASS), __FILE__, __LINE__,	\
 			       __FUNCTION__);				\
     __t; })

 #define TREE_RANGE_CHECK(T, CODE1, CODE2) __extension__			\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) < (CODE1) || TREE_CODE (__t) > (CODE2))		\
       tree_range_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,	\
 			       (CODE1), (CODE2));			\
     __t; })

 #define OMP_CLAUSE_SUBCODE_CHECK(T, CODE) __extension__			\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) != OMP_CLAUSE)					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,  	\
 			 OMP_CLAUSE, 0);				\
@@ -722,7 +722,7 @@ enum tree_node_structure_enum {
     __t; })

 #define OMP_CLAUSE_RANGE_CHECK(T, CODE1, CODE2) __extension__		\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TREE_CODE (__t) != OMP_CLAUSE)					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,  	\
 			 OMP_CLAUSE, 0);				\
@@ -734,7 +734,7 @@ enum tree_node_structure_enum {

 /* These checks have to be special cased.  */
 #define EXPR_CHECK(T) __extension__					\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     char const __c = TREE_CODE_CLASS (TREE_CODE (__t));			\
     if (!IS_EXPR_CODE_CLASS (__c))					\
       tree_class_check_failed (__t, tcc_expression, __FILE__, __LINE__,	\
@@ -742,7 +742,7 @@ enum tree_node_structure_enum {
     __t; })

 #define GIMPLE_STMT_CHECK(T) __extension__				\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     char const __c = TREE_CODE_CLASS (TREE_CODE (__t));			\
     if (!IS_GIMPLE_STMT_CODE_CLASS (__c))				\
       tree_class_check_failed (__t, tcc_gimple_stmt, __FILE__, __LINE__,\
@@ -751,14 +751,14 @@ enum tree_node_structure_enum {

 /* These checks have to be special cased.  */
 #define NON_TYPE_CHECK(T) __extension__					\
-({  const tree __t = (T);						\
+({  __typeof (T) const __t = (T);					\
     if (TYPE_P (__t))							\
       tree_not_class_check_failed (__t, tcc_type, __FILE__, __LINE__,	\
 				   __FUNCTION__);			\
     __t; })

 #define TREE_VEC_ELT_CHECK(T, I) __extension__				\
-(*({const tree __t = (T);						\
+(*({__typeof (T) const __t = (T);					\
     const int __i = (I);						\
     if (TREE_CODE (__t) != TREE_VEC)					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,		\
@@ -768,9 +768,9 @@ enum tree_node_structure_enum {
 				 __FILE__, __LINE__, __FUNCTION__);	\
     &__t->vec.a[__i]; }))

-#define PHI_NODE_ELT_CHECK(t, i) __extension__				\
-(*({const tree __t = t;							\
-    const int __i = (i);						\
+#define PHI_NODE_ELT_CHECK(T, I) __extension__				\
+(*({__typeof (T) const __t = (T);					\
+    const int __i = (I);						\
     if (TREE_CODE (__t) != PHI_NODE)					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,  	\
 			 PHI_NODE, 0);					\
@@ -779,9 +779,9 @@ enum tree_node_structure_enum {
 				 __FILE__, __LINE__, __FUNCTION__);	\
     &__t->phi.a[__i]; }))

-#define OMP_CLAUSE_ELT_CHECK(t, i) __extension__			\
-(*({const tree __t = t;							\
-    const int __i = (i);						\
+#define OMP_CLAUSE_ELT_CHECK(T, I) __extension__			\
+(*({__typeof (T) const __t = (T);						\
+    const int __i = (I);						\
     if (TREE_CODE (__t) != OMP_CLAUSE)					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__,  	\
 			 OMP_CLAUSE, 0);				\
@@ -792,7 +792,7 @@ enum tree_node_structure_enum {

 /* Special checks for TREE_OPERANDs.  */
 #define TREE_OPERAND_CHECK(T, I) __extension__				\
-(*({const tree __t = EXPR_CHECK (T);					\
+(*({__typeof (T) const __t = EXPR_CHECK (T);				\
     const int __i = (I);						\
     if (GIMPLE_TUPLE_P (__t))						\
       gcc_unreachable ();						\
@@ -802,7 +802,7 @@ enum tree_node_structure_enum {
     &__t->exp.operands[__i]; }))

 #define TREE_OPERAND_CHECK_CODE(T, CODE, I) __extension__		\
-(*({const tree __t = (T);						\
+(*({__typeof (T) const __t = (T);					\
     const int __i = (I);						\
     if (TREE_CODE (__t) != CODE)					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__, (CODE), 0);\
@@ -813,7 +813,7 @@ enum tree_node_structure_enum {

 /* Special checks for GIMPLE_STMT_OPERANDs.  */
 #define GIMPLE_STMT_OPERAND_CHECK(T, I) __extension__			\
-(*({const tree __t = GIMPLE_STMT_CHECK (T);				\
+(*({__typeof (T) const __t = GIMPLE_STMT_CHECK (T);			\
     const int __i = (I);						\
     if (__i < 0 || __i >= TREE_OPERAND_LENGTH (__t))			\
       tree_operand_check_failed (__i, __t,				\
@@ -822,7 +822,7 @@ enum tree_node_structure_enum {

 #define TREE_RTL_OPERAND_CHECK(T, CODE, I) __extension__		\
 (*(rtx *)								\
- ({const tree __t = (T);						\
+ ({__typeof (T) const __t = (T);					\
     const int __i = (I);						\
     if (TREE_CODE (__t) != (CODE))					\
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__, (CODE), 0); \
@@ -841,7 +841,7 @@ enum tree_node_structure_enum {
    are chained together.  */

 #define TREE_CHAIN(NODE) __extension__ \
-(*({const tree __t = (NODE);					\
+(*({__typeof (NODE) const __t = (NODE);				\
     if (GIMPLE_TUPLE_P (__t))					\
       gcc_unreachable ();					\
     &__t->common.chain; }))
@@ -851,7 +851,7 @@ enum tree_node_structure_enum {
    In ARRAY_TYPE nodes, this is the type of the elements.
    In VECTOR_TYPE nodes, this is the type of the elements.  */
 #define TREE_TYPE(NODE) __extension__ \
-(*({const tree __t = (NODE);					\
+(*({__typeof (NODE) const __t = (NODE);					\
     if (GIMPLE_TUPLE_P (__t))					\
       gcc_unreachable ();					\
     &__t->common.type; }))

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH INSTALLED]: const typedefs part 1/N
  2007-07-25 18:14 [PATCH INSTALLED]: const typedefs part 1/N Kaveh R. GHAZI
@ 2007-08-02  0:14 ` Andrew Pinski
  2007-08-02  0:18   ` Andrew Pinski
  2007-08-02 15:14   ` Kaveh R. GHAZI
  0 siblings, 2 replies; 8+ messages in thread
From: Andrew Pinski @ 2007-08-02  0:14 UTC (permalink / raw)
  To: Kaveh R. GHAZI; +Cc: gcc-patches

On 7/25/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> The patch below (and several upcoming ones) implement the core of the
> const typedefs project I proposed last year:
> http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00383.html

These sets of patches have caused a lot of warnings to show up while
compiling with GCC 3.3.3:
../../gcc/tree.h:4986: warning: duplicate `const'

etc.
Two reduced testcases come down to:
const int a;
__typeof(a) const c;

and:
typedef const int a;
a const c;

I was wondering if the trunk should be warning or not.  And maybe how
to get rid of the warnings for 3.3 building.  I am using 3.3.3 to
bootstrap GCC with so it slows down compiling the first stage by a
huge amount.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH INSTALLED]: const typedefs part 1/N
  2007-08-02  0:14 ` Andrew Pinski
@ 2007-08-02  0:18   ` Andrew Pinski
  2007-08-02 15:14   ` Kaveh R. GHAZI
  1 sibling, 0 replies; 8+ messages in thread
From: Andrew Pinski @ 2007-08-02  0:18 UTC (permalink / raw)
  To: Kaveh R. GHAZI; +Cc: gcc-patches

On 8/1/07, Andrew Pinski <pinskia@gmail.com> wrote:
> On 7/25/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> > The patch below (and several upcoming ones) implement the core of the
> > const typedefs project I proposed last year:
> > http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00383.html
>
> These sets of patches have caused a lot of warnings to show up while
> compiling with GCC 3.3.3:
> ../../gcc/tree.h:4986: warning: duplicate `const'
>
> etc.
> Two reduced testcases come down to:
> const int a;
> __typeof(a) const c;
>
> and:
> typedef const int a;
> a const c;
>
> I was wondering if the trunk should be warning or not.  And maybe how
> to get rid of the warnings for 3.3 building.  I am using 3.3.3 to
> bootstrap GCC with so it slows down compiling the first stage by a
> huge amount.
>
> Thanks,
> Andrew Pinski
>

I could have thought we compiled with -pedantic-errors anyways so it
should be erroring out with the trunk (the behavior changed with
http://gcc.gnu.org/ml/gcc/2004-03/msg00525.html to turn the warning on
for only -pedantic).

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH INSTALLED]: const typedefs part 1/N
  2007-08-02  0:14 ` Andrew Pinski
  2007-08-02  0:18   ` Andrew Pinski
@ 2007-08-02 15:14   ` Kaveh R. GHAZI
  2007-08-02 22:39     ` Kaveh R. GHAZI
  1 sibling, 1 reply; 8+ messages in thread
From: Kaveh R. GHAZI @ 2007-08-02 15:14 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Wed, 1 Aug 2007, Andrew Pinski wrote:

> These sets of patches have caused a lot of warnings to show up while
> compiling with GCC 3.3.3:
> ../../gcc/tree.h:4986: warning: duplicate `const'
>
> etc.
> Two reduced testcases come down to:
> const int a;
> __typeof(a) const c;
>
> and:
> typedef const int a;
> a const c;
>
> I was wondering if the trunk should be warning or not.  And maybe how
> to get rid of the warnings for 3.3 building.  I am using 3.3.3 to
> bootstrap GCC with so it slows down compiling the first stage by a
> huge amount.

I don't have 3.3.x handy, but I've compiled mainlne with 3.4.6 and I don't
see these diags.  Neither do they show up during bootstrap in stage2/3.

Also, I don't think your testcase is representative of the actual code
because it produces a diagnostic with my 3.4.6 and mainline using -W -Wall
-pedantic, whereas bootstrapping doesn't.  So something is different
between your testcase and mainline sources.  Maybe it's the code or maybe
your configure flags differ from mine, I dunno.  Most (all?) of the places
I used "__typeof() const" should have been on rtx and tree typedefs not
int.  That may be significant because e.g. tree is union tree_node * so
the const would be applied to the pointer variable being declared, not the
union.

Would you please give me a testcase that warns for 3.3.3 but does *not*
warn for mainline?  Meanwhile I'll build a 3.3.x and see if I can
reproduce it.

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH INSTALLED]: const typedefs part 1/N
  2007-08-02 15:14   ` Kaveh R. GHAZI
@ 2007-08-02 22:39     ` Kaveh R. GHAZI
  2007-08-02 22:43       ` Andrew Pinski
  0 siblings, 1 reply; 8+ messages in thread
From: Kaveh R. GHAZI @ 2007-08-02 22:39 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Thu, 2 Aug 2007, Kaveh R. GHAZI wrote:

> On Wed, 1 Aug 2007, Andrew Pinski wrote:
>
> > These sets of patches have caused a lot of warnings to show up while
> > compiling with GCC 3.3.3:
> > ../../gcc/tree.h:4986: warning: duplicate `const'
> >
> > etc.
> > Two reduced testcases come down to:
> > const int a;
> > __typeof(a) const c;
> >
> > and:
> > typedef const int a;
> > a const c;
> >
> > I was wondering if the trunk should be warning or not.  And maybe how
> > to get rid of the warnings for 3.3 building.  I am using 3.3.3 to
> > bootstrap GCC with so it slows down compiling the first stage by a
> > huge amount.
>
> I don't have 3.3.x handy, but I've compiled mainlne with 3.4.6 and I don't
> see these diags.  Neither do they show up during bootstrap in stage2/3.
>
> Also, I don't think your testcase is representative of the actual code
> because it produces a diagnostic with my 3.4.6 and mainline using -W -Wall
> -pedantic, whereas bootstrapping doesn't.  So something is different
> between your testcase and mainline sources.  Maybe it's the code or maybe
> your configure flags differ from mine, I dunno.  Most (all?) of the places
> I used "__typeof() const" should have been on rtx and tree typedefs not
> int.  That may be significant because e.g. tree is union tree_node * so
> the const would be applied to the pointer variable being declared, not the
> union.
>
> Would you please give me a testcase that warns for 3.3.3 but does *not*
> warn for mainline?  Meanwhile I'll build a 3.3.x and see if I can
> reproduce it.

Andrew,

I managed to reproduce this with 3.3.6.  The problem occurs with 3.0
through 3.3.  I verified that it does not occur with 2.95 and prior, or
with 3.4.0 or later.

As I suspected I was also able to verify that your testcase is not
relevant, in that the idiom using "__typeof(foo) const" does not occur
with foo=int.  It only occurs with e.g. tree or rtx.  The reason this is
important is that using an int will pedwarn with all gcc-3.x and 4.x
versions, whereas typedef'ed pointers follow the restricted versioning
pattern I described above.

Furthermore the "__typeof(x) const" code is only used inside
ENABLE_CHECKING guards, so users building a released mainline with 3.0
through 3.3 won't see it.  Only developers (such as yourself) building
stage1 with 3.0 through 3.3 and checking enabled will see extra warns (and
it's just warns not errors, albeit a lot of them).  I think it's important
to describe exactly when the problem occurs because it's limited to a very
specific set of circumstances.

Here is a proper testcase that only fails for 3.0 through 3.3:

	union tree_node;
	typedef union tree_node *tree;

	#define TREE_CHECK(d) __extension__ ({ __typeof (d) const _decl = (d); _decl; })

	void foo (tree foo)
	{
	  tree const t1 = foo;
	  union tree_node *const t2 = foo;
	  tree t3;

	  t3 = TREE_CHECK (t1);
	  t3 = TREE_CHECK (t2);
	}

GCC 3.0 - 3.3 warns for both assignments to t3.  IMHO, it's a bug for gcc
for warn like this, and it was properly fixed in 3.4.0.

I don't know that there is anything here left to fix.  I don't feel that
taking out the const qualifiers constitutes making the code more correct.
If the bogus warnings really bother you there are several options.

1.  Upgrade your bootstrap compiler to 3.4.0 or later.

2.  Configure with checking=release.

3.  If it bothers more people perhaps we could bump the ENABLE_CHECKING
guards to require 3.4 or later.  (Currently checking requires 2.7).


I don't like 3, can you live with #1?

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH INSTALLED]: const typedefs part 1/N
  2007-08-02 22:39     ` Kaveh R. GHAZI
@ 2007-08-02 22:43       ` Andrew Pinski
  2007-08-02 23:22         ` Chris Lattner
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Pinski @ 2007-08-02 22:43 UTC (permalink / raw)
  To: Kaveh R. GHAZI; +Cc: gcc-patches

On 8/2/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> GCC 3.0 - 3.3 warns for both assignments to t3.  IMHO, it's a bug for gcc
> for warn like this, and it was properly fixed in 3.4.0.

Why is it wrong for GCC to warn here?
We have typeof(tree const) const which has the duplicated const there.
I feel that there should be a warning in that case still.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH INSTALLED]: const typedefs part 1/N
  2007-08-02 22:43       ` Andrew Pinski
@ 2007-08-02 23:22         ` Chris Lattner
  2007-08-03  2:07           ` Kaveh R. GHAZI
  0 siblings, 1 reply; 8+ messages in thread
From: Chris Lattner @ 2007-08-02 23:22 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Kaveh R. GHAZI, gcc-patches


On Aug 2, 2007, at 3:43 PM, Andrew Pinski wrote:

> On 8/2/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
>> GCC 3.0 - 3.3 warns for both assignments to t3.  IMHO, it's a bug  
>> for gcc
>> for warn like this, and it was properly fixed in 3.4.0.
>
> Why is it wrong for GCC to warn here?
> We have typeof(tree const) const which has the duplicated const there.
> I feel that there should be a warning in that case still.

Isn't this logically the same case as:

typedef const int X;

  const X

?

-Chris

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH INSTALLED]: const typedefs part 1/N
  2007-08-02 23:22         ` Chris Lattner
@ 2007-08-03  2:07           ` Kaveh R. GHAZI
  0 siblings, 0 replies; 8+ messages in thread
From: Kaveh R. GHAZI @ 2007-08-03  2:07 UTC (permalink / raw)
  To: Chris Lattner; +Cc: Andrew Pinski, gcc-patches

On Thu, 2 Aug 2007, Chris Lattner wrote:

>
> On Aug 2, 2007, at 3:43 PM, Andrew Pinski wrote:
>
> > On 8/2/07, Kaveh R. GHAZI <ghazi@caip.rutgers.edu> wrote:
> >> GCC 3.0 - 3.3 warns for both assignments to t3.  IMHO, it's a bug
> >> for gcc
> >> for warn like this, and it was properly fixed in 3.4.0.
> >
> > Why is it wrong for GCC to warn here?
> > We have typeof(tree const) const which has the duplicated const there.
> > I feel that there should be a warning in that case still.
>
> Isn't this logically the same case as:
> typedef const int X;
>   const X
> ?
> -Chris

Yes, there is an inconsistency between how gcc handles types and pointers
to types when copying qualifiers for __typeof.  (I haven't even checked
how gcc handles multiple pointer indirections).  And as I've noted there
is an inconsistency between gcc versions too.  (The joy of yet another
poorly defined extension.)

I'm not sure we can make any change that won't break someone's code
somewhere.  But if we were to define it I'd say that the qualifiers get
copied for every layer of pointer indirection except the last one when we
reach the actual variable we're declaring.  (Please substitute the correct
standard-ese language here.)

E.g. that would mean:

const int -> int
const int *const -> const int*
const int *const *const -> const int*const*

I believe this would preserve const-safety while letting the programmer
reassign the variable if they wish or make it const in the declaration and
read-only if they wish.  I think the same logic can be applied to the
volatile qualifier.

Note: changing __typeof's behavior in mainline won't fix Andrew's issue.

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-08-03  2:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-25 18:14 [PATCH INSTALLED]: const typedefs part 1/N Kaveh R. GHAZI
2007-08-02  0:14 ` Andrew Pinski
2007-08-02  0:18   ` Andrew Pinski
2007-08-02 15:14   ` Kaveh R. GHAZI
2007-08-02 22:39     ` Kaveh R. GHAZI
2007-08-02 22:43       ` Andrew Pinski
2007-08-02 23:22         ` Chris Lattner
2007-08-03  2:07           ` Kaveh R. GHAZI

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).