public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Harden variably_modified_type_p
@ 2017-08-17 16:03 Richard Biener
  2017-08-17 18:27 ` Eric Botcazou
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2017-08-17 16:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: ebotcazou


It seems with Ada one can have cycles in types via pointer types
and calling variably_modified_type_p on such type recurses indefinitely.
The following is an attempt to fix that (albeit I'm not 100% sure
there's no caller of the function using TREE_VISITED itself).

Cures c38102a.adb with LTO early debug patches for me.

Any comments?  (no further testing sofar)

Richard.

Index: gcc/tree.c
===================================================================
--- gcc/tree.c	(revision 251141)
+++ gcc/tree.c	(working copy)
@@ -8597,8 +8601,16 @@ variably_modified_type_p (tree type, tre
     case POINTER_TYPE:
     case REFERENCE_TYPE:
     case VECTOR_TYPE:
+      /* Ada can have pointer types refering to themselves indirectly.  */
+      if (TREE_VISITED (type))
+	return false;
+      TREE_VISITED (type) = true;
       if (variably_modified_type_p (TREE_TYPE (type), fn))
-	return true;
+	{
+	  TREE_VISITED (type) = false;
+	  return true;
+	}
+      TREE_VISITED (type) = false;
       break;
 
     case FUNCTION_TYPE:

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

* Re: [PATCH] Harden variably_modified_type_p
  2017-08-17 16:03 [PATCH] Harden variably_modified_type_p Richard Biener
@ 2017-08-17 18:27 ` Eric Botcazou
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2017-08-17 18:27 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

> It seems with Ada one can have cycles in types via pointer types
> and calling variably_modified_type_p on such type recurses indefinitely.
> The following is an attempt to fix that (albeit I'm not 100% sure
> there's no caller of the function using TREE_VISITED itself).
> 
> Cures c38102a.adb with LTO early debug patches for me.
> 
> Any comments?  (no further testing sofar)

See walk_type_fields for a different approach to the same isse.

-- 
Eric Botcazou

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

end of thread, other threads:[~2017-08-17 16:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-17 16:03 [PATCH] Harden variably_modified_type_p Richard Biener
2017-08-17 18:27 ` Eric Botcazou

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