From 6835f8a04a062c3d3276a4a723a9237b1eaf835b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 29 Oct 2019 21:58:47 +0100 Subject: [PATCH] =?utf8?q?re=20PR=20c++/92201=20(ICE:=20=E2=80=98verify=5F?= =?utf8?q?gimple=E2=80=99=20failed=20with=20-std=3Dc++2a)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 6 ++++++ gcc/cp/cp-gimplify.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/other/pr92201.C | 7 +++++++ 4 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/other/pr92201.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 09d1c18e808..fda743b6872 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-10-29 Jakub Jelinek + + 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 PR c++/91548 - fix detecting modifying const objects for ARRAY_REF. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 9fc60c964e0..abd82b3fe42 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -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. */; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cffd5921772..3761a99bab1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-29 Jakub Jelinek + + PR c++/92201 + * g++.dg/other/pr92201.C: New test. + 2019-10-29 Marek Polacek 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 index 00000000000..15ba1a12525 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/pr92201.C @@ -0,0 +1,7 @@ +// PR c++/92201 + +int +foo (void (*p) ()) +{ + return (*reinterpret_cast (p)) (); +} -- 2.30.2