re PR c++/92201 (ICE: ‘verify_gimple’ failed with -std=c++2a)
authorJakub Jelinek <jakub@redhat.com>
Tue, 29 Oct 2019 20:58:47 +0000 (21:58 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 29 Oct 2019 20:58:47 +0000 (21:58 +0100)
PR c++/92201
* cp-gimplify.c (cp_gimplify_expr): If gimplify_to_rvalue changes the
function pointer type, re-add cast to the original one.

* g++.dg/other/pr92201.C: New test.

From-SVN: r277592

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/pr92201.C [new file with mode: 0644]

index 09d1c18e8083ed9777e04094badf953ade146829..fda743b6872dba0bc385375f306e3395c8c02b20 100644 (file)
@@ -1,3 +1,9 @@
+2019-10-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/92201
+       * cp-gimplify.c (cp_gimplify_expr): If gimplify_to_rvalue changes the
+       function pointer type, re-add cast to the original one.
+
 2019-10-29  Marek Polacek  <polacek@redhat.com>
 
        PR c++/91548 - fix detecting modifying const objects for ARRAY_REF.
index 9fc60c964e0f07c39befe8887089b6ac3c33d6d4..abd82b3fe424f6c1e970e5cff972fa2eb6766827 100644 (file)
@@ -838,11 +838,17 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
          && CALL_EXPR_FN (*expr_p)
          && cp_get_callee_fndecl_nofold (*expr_p) == NULL_TREE)
        {
+         tree fnptrtype = TREE_TYPE (CALL_EXPR_FN (*expr_p));
          enum gimplify_status t
            = gimplify_to_rvalue (&CALL_EXPR_FN (*expr_p), pre_p, NULL,
                                  is_gimple_call_addr);
          if (t == GS_ERROR)
            ret = GS_ERROR;
+         /* GIMPLE considers most pointer conversion useless, but for
+            calls we actually care about the exact function pointer type.  */
+         else if (TREE_TYPE (CALL_EXPR_FN (*expr_p)) != fnptrtype)
+           CALL_EXPR_FN (*expr_p)
+             = build1 (NOP_EXPR, fnptrtype, CALL_EXPR_FN (*expr_p));
        }
       if (!CALL_EXPR_FN (*expr_p))
        /* Internal function call.  */;
index cffd59217720bf96a26bcf5276bade8d558f2c0f..3761a99bab1823a1364a4bf765dca8f59f0de947 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/92201
+       * g++.dg/other/pr92201.C: New test.
+
 2019-10-29  Marek Polacek  <polacek@redhat.com>
 
        PR c++/91548 - fix detecting modifying const objects for ARRAY_REF.
diff --git a/gcc/testsuite/g++.dg/other/pr92201.C b/gcc/testsuite/g++.dg/other/pr92201.C
new file mode 100644 (file)
index 0000000..15ba1a1
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/92201
+
+int
+foo (void (*p) ())
+{
+  return (*reinterpret_cast<int (*)()> (p)) ();
+}