]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix broken conversion in coroutines
authorJason Merrill <jason@redhat.com>
Fri, 30 Sep 2022 14:04:22 +0000 (10:04 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 6 Oct 2022 21:43:14 +0000 (17:43 -0400)
You can't use CONVERT_EXPR to convert between two class types.

VIEW_CONVERT_EXPR takes liberties with the C++ type system, but is probably
safe in this context.  Let's also only use it when the type isn't already
what we want.

gcc/cp/ChangeLog:

* coroutines.cc (expand_one_await_expression): Change conversion
to VIEW_CONVERT_EXPR.
* cp-gimplify.cc (cp_genericize_r) [CONVERT_EXPR]: Add assert.

gcc/cp/coroutines.cc
gcc/cp/cp-gimplify.cc

index eca01abcb7a69f789a5c5f16abb8bede5b2f5b84..60b846600b923b30b2d692412d2ca28b66052542 100644 (file)
@@ -1728,7 +1728,10 @@ expand_one_await_expression (tree *stmt, tree *await_expr, void *d)
     }
   else
     {
-      r = build1_loc (loc, CONVERT_EXPR, void_coro_handle_type, suspend);
+      r = suspend;
+      if (!same_type_ignoring_top_level_qualifiers_p (susp_type,
+                                                     void_coro_handle_type))
+       r = build1_loc (loc, VIEW_CONVERT_EXPR, void_coro_handle_type, r);
       r = build2_loc (loc, INIT_EXPR, void_coro_handle_type, data->conthand, r);
       r = build1 (CONVERT_EXPR, void_type_node, r);
       append_to_statement_list (r, &body_list);
index b4599fc34d85cd316c06df3810c4b8500b75c960..5d26e59d098a325a91814dc423120a11de10b622 100644 (file)
@@ -1589,6 +1589,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
       break;
 
     case CONVERT_EXPR:
+      gcc_checking_assert (!AGGREGATE_TYPE_P (TREE_TYPE (stmt)));
       gcc_assert (!CONVERT_EXPR_VBASE_PATH (stmt));
       break;