public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Extend verify_type to check various uses of TYPE_MINVAL
@ 2015-05-03 16:08 Jan Hubicka
  2015-05-04 14:21 ` Rainer Orth
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Hubicka @ 2015-05-03 16:08 UTC (permalink / raw)
  To: gcc-patches

Hi,
this patch extends verify_type to check various uses of TYPE_MINVAL. 
I also added check that MIN_VALUE have compatible type with T:
 useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (TYPE_MIN_VALUE (t)))
but that one fails interesting ways for C sizetype. I will try to look
into this and thus this patch omits it.

The main motivation is to check that various frontend overrides of TYPE_MINVAL
are under control.

Bootstrapped/regtested x86_64-linux, will commit it as obvious.

Honza

	* tree.c (verify_type): Check various uses of TYPE_MINVAL.
Index: tree.c
===================================================================
--- tree.c	(revision 222723)
+++ tree.c	(working copy)
@@ -12584,15 +12584,60 @@ verify_type (const_tree t)
     }
   else if (t != mv && !verify_type_variant (t, mv))
     error_found = true;
-  /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
-     and danagle the pointer from time to time.  */
-  if (RECORD_OR_UNION_TYPE_P (t) && TYPE_VFIELD (t)
-      && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
-      && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
+
+  /* Check various uses of TYPE_MINVAL.  */
+  if (RECORD_OR_UNION_TYPE_P (t))
     {
-      error ("TYPE_VFIELD is not FIELD_DECL nor TREE_LIST");
-      debug_tree (TYPE_VFIELD (t));
+      /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS
+	 and danagle the pointer from time to time.  */
+      if (TYPE_VFIELD (t)
+	  && TREE_CODE (TYPE_VFIELD (t)) != FIELD_DECL
+	  && TREE_CODE (TYPE_VFIELD (t)) != TREE_LIST)
+	{
+	  error ("TYPE_VFIELD is not FIELD_DECL nor TREE_LIST");
+	  debug_tree (TYPE_VFIELD (t));
+	  error_found = true;
+	}
     }
+  else if (TREE_CODE (t) == POINTER_TYPE)
+    {
+      if (TYPE_NEXT_PTR_TO (t)
+	  && TREE_CODE (TYPE_NEXT_PTR_TO (t)) != POINTER_TYPE)
+	{
+	  error ("TYPE_NEXT_PTR_TO is not POINTER_TYPE");
+	  debug_tree (TYPE_NEXT_PTR_TO (t));
+	  error_found = true;
+	}
+    }
+  else if (TREE_CODE (t) == REFERENCE_TYPE)
+    {
+      if (TYPE_NEXT_REF_TO (t)
+	  && TREE_CODE (TYPE_NEXT_REF_TO (t)) != REFERENCE_TYPE)
+	{
+	  error ("TYPE_NEXT_REF_TO is not REFERENCE_TYPE");
+	  debug_tree (TYPE_NEXT_REF_TO (t));
+	  error_found = true;
+	}
+    }
+  else if (INTEGRAL_TYPE_P (t) || TREE_CODE (t) == REAL_TYPE || TREE_CODE (t) == FIXED_POINT_TYPE)
+    {
+      if (!TYPE_MIN_VALUE (t))
+	;
+      else if (!TREE_CONSTANT (TYPE_MIN_VALUE (t)))
+        {
+	  error ("TYPE_MIN_VALUE is not constant");
+	  debug_tree (TYPE_MIN_VALUE (t));
+	  error_found = true;
+        }
+    }
+  else if (TYPE_MINVAL (t))
+    {
+      error ("TYPE_MINVAL non-NULL");
+      debug_tree (TYPE_MINVAL (t));
+      error_found = true;
+    }
+
+
   if (error_found)
     {
       debug_tree (const_cast <tree> (t));

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

* Re: Extend verify_type to check various uses of TYPE_MINVAL
  2015-05-03 16:08 Extend verify_type to check various uses of TYPE_MINVAL Jan Hubicka
@ 2015-05-04 14:21 ` Rainer Orth
  2015-05-04 14:50   ` Eric Botcazou
  0 siblings, 1 reply; 5+ messages in thread
From: Rainer Orth @ 2015-05-04 14:21 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

Jan Hubicka <hubicka@ucw.cz> writes:

> Hi,
> this patch extends verify_type to check various uses of TYPE_MINVAL. 
> I also added check that MIN_VALUE have compatible type with T:
>  useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (TYPE_MIN_VALUE (t)))
> but that one fails interesting ways for C sizetype. I will try to look
> into this and thus this patch omits it.
>
> The main motivation is to check that various frontend overrides of TYPE_MINVAL
> are under control.
>
> Bootstrapped/regtested x86_64-linux, will commit it as obvious.

Not obvious enough, it seems: this patch broke gnat.dg/lto* tests at
least on i386-pc-solaris2.10.  E.g.

FAIL: gnat.dg/lto1.adb (test for excess errors)
WARNING: gnat.dg/lto1.adb compilation failed to produce executable

FAIL: gnat.dg/lto1.adb (test for excess errors)
Excess errors:
/vol/gcc/src/hg/trunk/solaris/gcc/testsuite/gnat.dg/lto1_pkg.adb:23:1: error: TYPE_MIN_VALUE is not constant
 <placeholder_expr feb2b9b0
    type <integer_type fea16000 sizetype public unsigned SI
        size <integer_cst fea041cc constant 32>
        unit size <integer_cst fea041e0 constant 4>
        align 32 symtab 0 alias set -1 canonical type fea16000 precision 32 min <integer_cst fea041f4 0> max <integer_cst fea04000 4294967295>>
   >
 <integer_type feb67ba0 lto1_pkg__Tfiltering_levels_tB___UB0
    type <integer_type fea16000 sizetype public unsigned SI
        size <integer_cst fea041cc constant 32>
        unit size <integer_cst fea041e0 constant 4>
        align 32 symtab 0 alias set -1 canonical type fea16000 precision 32 min <integer_cst fea041f4 0> max <integer_cst fea04000 4294967295>>
    sizes-gimplified visited SI size <integer_cst fea041cc 32> unit size <integer_cst fea041e0 4>
    align 32 symtab 0 alias set -1 canonical type feb67ba0 precision 32 min <placeholder_expr feb2b9b0> max <placeholder_expr feb2b9c0>
    index type <integer_type feb67b40
        type <enumeral_type feb67960 lto1_pkg__filtering_level_t sizes-gimplified visited unsigned QI
            size <integer_cst fea042d0 constant 8>
            unit size <integer_cst fea042e4 constant 1>
            align 8 symtab 0 alias set -1 canonical type feb67960 precision 8 min <integer_cst feb60e4c 0> max <integer_cst feb60f3c 255>
            values <tree_list feb648e8
                purpose <identifier_node feb639d8 lto1_pkg__none>
                value <integer_cst feb60e4c constant visited 0>
                chain <tree_list feb64918
                    purpose <identifier_node feb639f4 lto1_pkg__pr_in_clutter>
                    value <integer_cst feb60f50 constant 1>
                    chain <tree_list feb64930
                        purpose <identifier_node feb63a10 lto1_pkg__ssr_plots>
                        value <integer_cst feb60f78 constant 2>
                        chain <tree_list feb64948 purpose <identifier_node feb63a2c lto1_pkg__pr_plots> value <integer_cst feb60fa0 3>>>>> context <translation_unit_decl fed805f0 D.18>
            chain <type_decl feb687e8 lto1_pkg__filtering_level_t>>
        QI size <integer_cst fea042d0 8> unit size <integer_cst fea042e4 1>
        align 8 symtab 0 alias set -1 canonical type feb67b40 precision 8 min <integer_cst feb60e4c 0> max <integer_cst feb60fa0 3> RM min <component_ref feb63a9c> RM max <component_ref feb63ab8>>
    chain <type_decl feb68a10 D.4194>>

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

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

* Re: Extend verify_type to check various uses of TYPE_MINVAL
  2015-05-04 14:21 ` Rainer Orth
@ 2015-05-04 14:50   ` Eric Botcazou
  2015-05-04 23:50     ` Jan Hubicka
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Botcazou @ 2015-05-04 14:50 UTC (permalink / raw)
  To: Rainer Orth; +Cc: gcc-patches, Jan Hubicka

> Not obvious enough, it seems: this patch broke gnat.dg/lto* tests at
> least on i386-pc-solaris2.10.  E.g.
> 
> FAIL: gnat.dg/lto1.adb (test for excess errors)
> WARNING: gnat.dg/lto1.adb compilation failed to produce executable
> 
> FAIL: gnat.dg/lto1.adb (test for excess errors)
> Excess errors:
> /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/gnat.dg/lto1_pkg.adb:23:1:
> error: TYPE_MIN_VALUE is not constant 

TYPE_MIN_VALUE can be arbitrary in Ada, with or without LTO.  For

package Q is

   function LB return Natural;
   function UB return Natural;

end Q;
with Q;

package P is

   type Arr1 is array (Natural range <>) of Boolean;

   subtype Arr2 is Arr1 (Q.LB .. Q.UB);

end P;

the TYPE_DOMAIN of Arr2 is

    domain <integer_type 0x7ffff69be000 type <integer_type 0x7ffff6d0e0a8 
sizetype>
        sizes-gimplified visited DI size <integer_cst 0x7ffff6d0abb8 64> unit 
size <integer_cst 0x7ffff6d0abd0 8>
        align 64 symtab 0 alias set -1 canonical type 0x7ffff69be000 precision 
64 min <nop_expr 0x7ffff69bd000> max <cond_expr 0x7ffff69b9420>

-- 
Eric Botcazou

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

* Re: Extend verify_type to check various uses of TYPE_MINVAL
  2015-05-04 14:50   ` Eric Botcazou
@ 2015-05-04 23:50     ` Jan Hubicka
  2015-05-05  1:48       ` Jan Hubicka
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Hubicka @ 2015-05-04 23:50 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: Rainer Orth, gcc-patches, Jan Hubicka

> > Not obvious enough, it seems: this patch broke gnat.dg/lto* tests at
> > least on i386-pc-solaris2.10.  E.g.
> > 
> > FAIL: gnat.dg/lto1.adb (test for excess errors)
> > WARNING: gnat.dg/lto1.adb compilation failed to produce executable
> > 
> > FAIL: gnat.dg/lto1.adb (test for excess errors)
> > Excess errors:
> > /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/gnat.dg/lto1_pkg.adb:23:1:
> > error: TYPE_MIN_VALUE is not constant 
> 
> TYPE_MIN_VALUE can be arbitrary in Ada, with or without LTO.  For
> 
> package Q is
> 
>    function LB return Natural;
>    function UB return Natural;
> 
> end Q;
> with Q;
> 
> package P is
> 
>    type Arr1 is array (Natural range <>) of Boolean;
> 
>    subtype Arr2 is Arr1 (Q.LB .. Q.UB);
> 
> end P;
> 
> the TYPE_DOMAIN of Arr2 is
> 
>     domain <integer_type 0x7ffff69be000 type <integer_type 0x7ffff6d0e0a8 
> sizetype>
>         sizes-gimplified visited DI size <integer_cst 0x7ffff6d0abb8 64> unit 
> size <integer_cst 0x7ffff6d0abd0 8>
>         align 64 symtab 0 alias set -1 canonical type 0x7ffff69be000 precision 
> 64 min <nop_expr 0x7ffff69bd000> max <cond_expr 0x7ffff69b9420>

Thanks, I just noticed the failures.  I will revert that check, it is indeed valid
for min values to not be constants (and even in C max values may be variable)

Honza

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

* Re: Extend verify_type to check various uses of TYPE_MINVAL
  2015-05-04 23:50     ` Jan Hubicka
@ 2015-05-05  1:48       ` Jan Hubicka
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Hubicka @ 2015-05-05  1:48 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: Eric Botcazou, Rainer Orth, gcc-patches

Hi,
if my wifi connectoin allows, I will commit the following patch I tested in
meantime.  It also adds sanity checking for TYPE_MAXVAL that does not seem to
trigger any issues anymore.

From type_non_common it remains to check values and binfo. I hope to kill all
those fields and move them to derived structures where they belong but it is
harder than it seems because way obj-c++ shares datastructures with C++ and C
FEs and abuse these fields in interesting ways. (I got stuck on these last
stage1)

Honza

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 222791)
+++ ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2015-05-02  Jan Hubicka  <hubicka@ucw.cz>
+
+	* tree.c (verify_type): Check various uses of TYPE_MAXVAL;
+	fix overactive TYPE_MIN_VALUE check and add FIXME for type
+	compatibility problems.
+
 2015-05-04  Ajit Agarwal  <ajitkum@xilinx.com>
 
 	* config/microblaze/microblaze.md (cbranchsi4): Added immediate
Index: tree.c
===================================================================
--- tree.c	(revision 222753)
+++ tree.c	(working copy)
@@ -12621,14 +12621,9 @@ verify_type (const_tree t)
     }
   else if (INTEGRAL_TYPE_P (t) || TREE_CODE (t) == REAL_TYPE || TREE_CODE (t) == FIXED_POINT_TYPE)
     {
-      if (!TYPE_MIN_VALUE (t))
-	;
-      else if (!TREE_CONSTANT (TYPE_MIN_VALUE (t)))
-        {
-	  error ("TYPE_MIN_VALUE is not constant");
-	  debug_tree (TYPE_MIN_VALUE (t));
-	  error_found = true;
-        }
+      /* FIXME: The following check should pass:
+	  useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (TYPE_MIN_VALUE (t))
+	 bud does not for C sizetypes in LTO.  */
     }
   else if (TYPE_MINVAL (t))
     {
@@ -12637,6 +12632,62 @@ verify_type (const_tree t)
       error_found = true;
     }
 
+  /* Check various uses of TYPE_MAXVAL.  */
+  if (RECORD_OR_UNION_TYPE_P (t))
+    {
+      if (TYPE_METHODS (t) && TREE_CODE (TYPE_METHODS (t)) != FUNCTION_DECL
+	  && TREE_CODE (TYPE_METHODS (t)) != TEMPLATE_DECL)
+	{
+	  error ("TYPE_METHODS is not FUNCTION_DECL nor TEMPLATE_DECL");
+	  debug_tree (TYPE_METHODS (t));
+	  error_found = true;
+	}
+    }
+  else if (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE)
+    {
+      if (TYPE_METHOD_BASETYPE (t)
+	  && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != RECORD_TYPE
+	  && TREE_CODE (TYPE_METHOD_BASETYPE (t)) != UNION_TYPE)
+	{
+	  error ("TYPE_METHOD_BASETYPE is not record nor union");
+	  debug_tree (TYPE_METHOD_BASETYPE (t));
+	  error_found = true;
+	}
+    }
+  else if (TREE_CODE (t) == OFFSET_TYPE)
+    {
+      if (TYPE_OFFSET_BASETYPE (t)
+	  && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != RECORD_TYPE
+	  && TREE_CODE (TYPE_OFFSET_BASETYPE (t)) != UNION_TYPE)
+	{
+	  error ("TYPE_OFFSET_BASETYPE is not record nor union");
+	  debug_tree (TYPE_OFFSET_BASETYPE (t));
+	  error_found = true;
+	}
+    }
+  else if (INTEGRAL_TYPE_P (t) || TREE_CODE (t) == REAL_TYPE || TREE_CODE (t) == FIXED_POINT_TYPE)
+    {
+      /* FIXME: The following check should pass:
+	  useless_type_conversion_p (const_cast <tree> (t), TREE_TYPE (TYPE_MAX_VALUE (t))
+	 bud does not for C sizetypes in LTO.  */
+    }
+  else if (TREE_CODE (t) == ARRAY_TYPE)
+    {
+      if (TYPE_ARRAY_MAX_SIZE (t)
+	  && TREE_CODE (TYPE_ARRAY_MAX_SIZE (t)) != INTEGER_CST)
+        {
+	  error ("TYPE_ARRAY_MAX_SIZE not INTEGER_CST");
+	  debug_tree (TYPE_ARRAY_MAX_SIZE (t));
+	  error_found = true;
+        } 
+    }
+  else if (TYPE_MAXVAL (t))
+    {
+      error ("TYPE_MAXVAL non-NULL");
+      debug_tree (TYPE_MAXVAL (t));
+      error_found = true;
+    }
+
 
   if (error_found)
     {

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

end of thread, other threads:[~2015-05-05  1:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-03 16:08 Extend verify_type to check various uses of TYPE_MINVAL Jan Hubicka
2015-05-04 14:21 ` Rainer Orth
2015-05-04 14:50   ` Eric Botcazou
2015-05-04 23:50     ` Jan Hubicka
2015-05-05  1:48       ` Jan Hubicka

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).