public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 60218
@ 2015-12-08 22:21 Paolo Carlini
  2015-12-09 14:24 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2015-12-08 22:21 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

Hi,

I while ago I tested a few fixes for minor ICEs affecting the __bases 
extension. This one is about an ICE during error recovery when the 
TYPE_BINFO information is not set yet. Still passes testing on x86_64-linux.

Thanks,
Paolo.

////////////////////////////

[-- Attachment #2: CL_60218 --]
[-- Type: text/plain, Size: 345 bytes --]

/cp
2015-12-08  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/60218
	* semantics.c (calculate_bases_helper): Don't call dfs_walk_all
	when TYPE_BINFO (type) is null.
	(calculate_bases): Handle gracefully a null vector->length ().

/testsuite
2015-12-08  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/60218
	* g++.dg/ext/bases2.C: New.

[-- Attachment #3: patch_60218 --]
[-- Type: text/plain, Size: 1838 bytes --]

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 231430)
+++ cp/semantics.c	(working copy)
@@ -3851,8 +3851,9 @@ calculate_bases_helper (tree type)
   vec<tree, va_gc> *vector = make_tree_vector();
 
   /* Now add non-virtual base classes in order of construction */
-  dfs_walk_all (TYPE_BINFO (type),
-                dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
+  if (TYPE_BINFO (type))
+    dfs_walk_all (TYPE_BINFO (type),
+		  dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
   return vector;
 }
 
@@ -3886,13 +3887,18 @@ calculate_bases (tree type)
   vec_safe_splice (vector, nonvbases);
   release_tree_vector (nonvbases);
 
-  /* Last element is entire class, so don't copy */
-  bases_vec = make_tree_vec (vector->length () - 1);
+  /* Note that during error recovery vector->length can even be zero.  */
+  if (vector->length () > 1)
+    {
+      /* Last element is entire class, so don't copy */
+      bases_vec = make_tree_vec (vector->length() - 1);
 
-  for (i = 0; i < vector->length () - 1; ++i)
-    {
-      TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
+      for (i = 0; i < vector->length () - 1; ++i)
+	TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
     }
+  else
+    bases_vec = make_tree_vec (0);
+
   release_tree_vector (vector);
   return bases_vec;
 }
Index: testsuite/g++.dg/ext/bases2.C
===================================================================
--- testsuite/g++.dg/ext/bases2.C	(revision 0)
+++ testsuite/g++.dg/ext/bases2.C	(working copy)
@@ -0,0 +1,14 @@
+// PR c++/60218
+// { dg-do compile { target c++11 } }
+
+template<typename...> struct A {};
+
+template<typename T> struct B
+{
+  typedef A<__bases(T)...> C;
+};
+
+struct X {};
+struct Y : X* {};  // { dg-error "expected" }
+
+B<Y> b;

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

* Re: [C++ Patch] PR 60218
  2015-12-08 22:21 [C++ Patch] PR 60218 Paolo Carlini
@ 2015-12-09 14:24 ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2015-12-09 14:24 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

OK

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

* [C++ Patch] PR 60218
@ 2015-01-19 18:11 Paolo Carlini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Carlini @ 2015-01-19 18:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 321 bytes --]

Hi,

looks like the __bases extensions need some work as regards error 
checking / recovery but this specific ICE on invalid seems easy and safe 
to fix: check that TYPE_BINFO isn't null and handle the possibility of 
vector->length () null during error recovery.

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////

[-- Attachment #2: CL_60218 --]
[-- Type: text/plain, Size: 345 bytes --]

/cp
2015-01-19  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/60218
	* semantics.c (calculate_bases_helper): Don't call dfs_walk_all
	when TYPE_BINFO (type) is null.
	(calculate_bases): Handle gracefully a null vector->length ().

/testsuite
2015-01-19  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/60218
	* g++.dg/ext/bases2.C: New.

[-- Attachment #3: patch_60218 --]
[-- Type: text/plain, Size: 1835 bytes --]

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 219849)
+++ cp/semantics.c	(working copy)
@@ -3804,8 +3804,9 @@ calculate_bases_helper (tree type)
   vec<tree, va_gc> *vector = make_tree_vector();
 
   /* Now add non-virtual base classes in order of construction */
-  dfs_walk_all (TYPE_BINFO (type),
-                dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
+  if (TYPE_BINFO (type))
+    dfs_walk_all (TYPE_BINFO (type),
+		  dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
   return vector;
 }
 
@@ -3839,13 +3840,18 @@ calculate_bases (tree type)
   vec_safe_splice (vector, nonvbases);
   release_tree_vector (nonvbases);
 
-  /* Last element is entire class, so don't copy */
-  bases_vec = make_tree_vec (vector->length () - 1);
+  /* NB: vector->length () can even be zero during error recovery.  */
+  if (vector->length () > 1)
+    {
+      /* Last element is entire class, so don't copy */
+      bases_vec = make_tree_vec (vector->length() - 1);
 
-  for (i = 0; i < vector->length () - 1; ++i)
-    {
-      TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
+      for (i = 0; i < vector->length () - 1; ++i)
+	TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
     }
+  else
+    bases_vec = make_tree_vec (0);
+
   release_tree_vector (vector);
   return bases_vec;
 }
Index: testsuite/g++.dg/ext/bases2.C
===================================================================
--- testsuite/g++.dg/ext/bases2.C	(revision 0)
+++ testsuite/g++.dg/ext/bases2.C	(working copy)
@@ -0,0 +1,14 @@
+// PR c++/60218
+// { dg-do compile { target c++11 } }
+
+template<typename...> struct A {};
+
+template<typename T> struct B
+{
+  typedef A<__bases(T)...> C;
+};
+
+struct X {};
+struct Y : X* {};  // { dg-error "expected" }
+
+B<Y> b;

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

end of thread, other threads:[~2015-12-09 14:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-08 22:21 [C++ Patch] PR 60218 Paolo Carlini
2015-12-09 14:24 ` Jason Merrill
  -- strict thread matches above, loose matches on Subject: below --
2015-01-19 18:11 Paolo Carlini

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