diff mbox

RFA: PATCH to gimple_canonical_types_compatible_p for middle-end/66214

Message ID 5655DA06.4000506@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 25, 2015, 3:55 p.m. UTC
The problem here is that we're trying to compare the TYPE_FIELDS of two 
variants of an incomplete type, which doesn't make sense; we shouldn't 
expect TYPE_FIELDS of an incomplete type to be meaningful.

Tested x86_64-pc-linux-gnu.  OK for trunk?

Comments

Jan Hubicka Nov. 25, 2015, 7:10 p.m. UTC | #1
> The problem here is that we're trying to compare the TYPE_FIELDS of
> two variants of an incomplete type, which doesn't make sense; we
> shouldn't expect TYPE_FIELDS of an incomplete type to be meaningful.
> 
> Tested x86_64-pc-linux-gnu.  OK for trunk?

> commit c6f5cd55d0bbebc2fa46628ebb8fdec2a44abf3a
> Author: Jason Merrill <jason@redhat.com>
> Date:   Wed Nov 25 10:47:03 2015 -0500
> 
>     	PR middle-end/66214
>     
>     	* tree.c (gimple_canonical_types_compatible_p) [RECORD_TYPE]:
>     	Don't try to compare the fields of incomplete types.

This makes sense to me.  I would still add a check that incomplete types have to
TYPE_FIELDS during LTO so we are sure that all types are either completed or
have no fields at all once the frontends are done.

Honza
Richard Biener Nov. 26, 2015, 9:33 a.m. UTC | #2
On Wed, Nov 25, 2015 at 4:55 PM, Jason Merrill <jason@redhat.com> wrote:
> The problem here is that we're trying to compare the TYPE_FIELDS of two
> variants of an incomplete type, which doesn't make sense; we shouldn't
> expect TYPE_FIELDS of an incomplete type to be meaningful.
>
> Tested x86_64-pc-linux-gnu.  OK for trunk?

Hmm, originally the code wasn't supposed to be called for incomplete types
as you generally can't compare them.  But now that the verifier uses the
predicate it instead should have this guard.

Richard.
diff mbox

Patch

commit c6f5cd55d0bbebc2fa46628ebb8fdec2a44abf3a
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 25 10:47:03 2015 -0500

    	PR middle-end/66214
    
    	* tree.c (gimple_canonical_types_compatible_p) [RECORD_TYPE]:
    	Don't try to compare the fields of incomplete types.

diff --git a/gcc/testsuite/g++.dg/debug/pr66214.C b/gcc/testsuite/g++.dg/debug/pr66214.C
new file mode 100644
index 0000000..79975b0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/pr66214.C
@@ -0,0 +1,10 @@ 
+// PR middle-end/66214
+
+typedef struct bn_gencb_st BN_GENCB;
+
+struct bn_gencb_st {
+  void *arg;
+  union U {
+    int (*cb_2)(int, int, BN_GENCB *);
+  };
+};
diff --git a/gcc/tree.c b/gcc/tree.c
index 2387deb..e918e1b 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -13424,6 +13424,11 @@  gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
       {
 	tree f1, f2;
 
+	/* Don't try to compare variants of an incomplete type, before
+	   TYPE_FIELDS has been copied around.  */
+	if (!COMPLETE_TYPE_P (t1) && !COMPLETE_TYPE_P (t2))
+	  return true;
+
 	if (TYPE_REVERSE_STORAGE_ORDER (t1) != TYPE_REVERSE_STORAGE_ORDER (t2))
 	  return false;