diff mbox series

checking: avoid verify_type_variant crash on incomplete type.

Message ID 20200126042120.8397-1-jason@redhat.com
State New
Headers show
Series checking: avoid verify_type_variant crash on incomplete type. | expand

Commit Message

Jason Merrill Jan. 26, 2020, 4:21 a.m. UTC
Here, we end up calling gen_type_die_with_usage for a type that's in the
middle of finish_struct_1, after we set TYPE_NEEDS_CONSTRUCTING on it but
before we copy all the flags to the variants--and, significantly, before we
set its TYPE_SIZE.  It seems reasonable to only look at
TYPE_NEEDS_CONSTRUCTING on complete types, since we aren't going to try to
create an object of an incomplete type any other way.

Tested x86_64-pc-linux-gnu, OK for trunk/9?

	PR c++/92601
	* tree.c (verify_type_variant): Only verify TYPE_NEEDS_CONSTRUCTING
	of complete types.
---
 gcc/testsuite/g++.dg/debug/verify1.C | 64 ++++++++++++++++++++++++++++
 gcc/tree.c                           |  2 +-
 2 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/debug/verify1.C


base-commit: 9c1179c339e050e2ce7c545f648b684d38dec69d

Comments

Jeff Law Jan. 26, 2020, 4:44 p.m. UTC | #1
On Sat, 2020-01-25 at 23:21 -0500, Jason Merrill wrote:
> Here, we end up calling gen_type_die_with_usage for a type that's in the
> middle of finish_struct_1, after we set TYPE_NEEDS_CONSTRUCTING on it but
> before we copy all the flags to the variants--and, significantly, before we
> set its TYPE_SIZE.  It seems reasonable to only look at
> TYPE_NEEDS_CONSTRUCTING on complete types, since we aren't going to try to
> create an object of an incomplete type any other way.
> 
> Tested x86_64-pc-linux-gnu, OK for trunk/9?
> 
> 	PR c++/92601
> 	* tree.c (verify_type_variant): Only verify TYPE_NEEDS_CONSTRUCTING
> 	of complete types.
OK
Jeff
>
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/debug/verify1.C b/gcc/testsuite/g++.dg/debug/verify1.C
new file mode 100644
index 00000000000..67e407251a1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/verify1.C
@@ -0,0 +1,64 @@ 
+// PR c++/92601
+// { dg-additional-options "-g -fchecking -std=c++17" }
+
+typedef int size_t;
+template <typename, int __v> struct integral_constant {
+  static constexpr int value = __v;
+};
+template <typename> struct A;
+template <typename _Tp> using __remove_cv_t = typename A<_Tp>::type;
+template <typename _Tp, typename _Up>
+struct B : integral_constant<bool, __is_same_as(_Tp, _Up)> {};
+template <typename...> class tuple;
+template <typename> struct A {
+  using type = tuple<const char *, const char *>;
+};
+template <typename> struct C { typedef __remove_cv_t<int> __type; };
+template <typename _Tp> class D {
+public:
+  typedef typename C<_Tp>::__type type;
+};
+template <bool> struct enable_if;
+template <int> struct F {};
+template <typename, typename> class G {
+public:
+  int operator*();
+  void operator++();
+};
+template <typename _Iterator, typename _Container>
+bool operator!=(G<_Iterator, _Container>, G<_Iterator, _Container>);
+template <typename> class H;
+template <typename = H<tuple<const char *, const char *>>> class vector {
+public:
+  typedef G<int, vector> iterator;
+  iterator begin();
+  iterator end();
+};
+template <typename> struct pack_c { typedef pack_c type; };
+template <typename, typename> struct make_index_pack_join;
+template <size_t... Left, size_t... Right>
+struct make_index_pack_join<pack_c<size_t, Left...>, pack_c<size_t, Right...>>
+    : pack_c<size_t> {};
+template <int N>
+struct I
+    : make_index_pack_join<typename I<N / 2>::type, typename I<N / 2>::type> {};
+template <> struct I<1> : pack_c<size_t> {};
+template <typename TTuple, typename>
+struct are_tuples_compatible_not_same
+    : F<B<typename D<TTuple>::type, int>::value> {};
+template <typename...> struct tuple_impl;
+template <size_t... Is, typename... Ts>
+struct tuple_impl<pack_c<size_t, Is...>, Ts...> {
+  template <typename UTuple, typename enable_if<are_tuples_compatible_not_same<
+                                 tuple<>, UTuple>::value>::type>
+  tuple_impl(UTuple &&);
+};
+template <typename... Ts> class tuple {
+  tuple_impl<typename I<sizeof...(Ts)>::type> _impl;
+  tuple(tuple &) = default;
+};
+vector message_handler_registrations;
+void fn1() {
+  for (auto t : message_handler_registrations)
+    ;
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 0ddf002e9eb..298499fe876 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -13881,9 +13881,9 @@  verify_type_variant (const_tree t, tree tv)
 	  debug_tree (TYPE_SIZE_UNIT (t));
 	  return false;
 	}
+      verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
     }
   verify_variant_match (TYPE_PRECISION);
-  verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
   if (RECORD_OR_UNION_TYPE_P (t))
     verify_variant_match (TYPE_TRANSPARENT_AGGR);
   else if (TREE_CODE (t) == ARRAY_TYPE)