From b8daf3d80b6daa9fab3e523586d1f570de43a9cb Mon Sep 17 00:00:00 2001 From: bergner Date: Thu, 29 Jun 2017 12:58:32 +0000 Subject: [PATCH] gcc/ PR middle-end/81194 * cfgexpand.c (expand_gimple_stmt_1): Handle switch statements with only one label. * stmt.c (expand_case): Assert NCASES is greater than one. gcc/testsuite/ PR middle-end/81194 * g++.dg/pr81194.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249783 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++ gcc/cfgexpand.c | 8 +++++- gcc/stmt.c | 5 +++- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/pr81194.C | 60 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr81194.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 578068bd343..c11b478777a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-06-29 Peter Bergner + + PR middle-end/81194 + * cfgexpand.c (expand_gimple_stmt_1): Handle switch statements + with only one label. + * stmt.c (expand_case): Assert NCASES is greater than one. + 2017-06-29 Richard Biener * tree-cfg.c (group_case_labels_stmt): Return whether we changed diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index c1f80727d30..d61c261a172 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -3566,7 +3566,13 @@ expand_gimple_stmt_1 (gimple *stmt) case GIMPLE_PREDICT: break; case GIMPLE_SWITCH: - expand_case (as_a (stmt)); + { + gswitch *swtch = as_a (stmt); + if (gimple_switch_num_labels (swtch) == 1) + expand_goto (CASE_LABEL (gimple_switch_default_label (swtch))); + else + expand_case (swtch); + } break; case GIMPLE_ASM: expand_asm_stmt (as_a (stmt)); diff --git a/gcc/stmt.c b/gcc/stmt.c index 9b5157d345b..fdf29a5c837 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -1142,7 +1142,10 @@ expand_case (gswitch *stmt) /* cleanup_tree_cfg removes all SWITCH_EXPR with their index expressions being INTEGER_CST. */ gcc_assert (TREE_CODE (index_expr) != INTEGER_CST); - + + /* Optimization of switch statements with only one label has already + occurred, so we should never see them at this point. */ + gcc_assert (ncases > 1); do_pending_stack_adjust (); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ad77af28b93..2f0b29ba700 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-29 Peter Bergner + + PR middle-end/81194 + * g++.dg/pr81194.C: New test. + 2017-06-29 H.J. Lu PR ipa/80565 diff --git a/gcc/testsuite/g++.dg/pr81194.C b/gcc/testsuite/g++.dg/pr81194.C new file mode 100644 index 00000000000..249fcf3b7c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr81194.C @@ -0,0 +1,60 @@ +// { dg-do compile } +// { dg-options "-O2 -std=c++17 -fno-exceptions" } + +template struct b { typedef a *c; }; +class e {}; +template class d { +public: + typedef typename b::c c; + c begin(); + c end(); +}; +struct f { + enum { g } h; +}; +struct i { + d j(); +}; +struct l { + d k(); +}; +class ac; +class o { +public: + o(int *, int *, int *, ac *); +}; +class ac { +public: + ac(e); + virtual o *ae(int *, int *, int *, int *); +}; +class p { + void af(f *m) { + switch (m->h) + case f::g: + ag(); + } + +public: + void n() { + l ah; + for (i *ai : ah.k()) + for (f *m : ai->j()) + af(m); + } + virtual void ag() { __builtin_unreachable(); } +}; +template class an : o { +public: + an(int *, int *, int *, int *, ac *); +}; +class q : ac { +public: + q() : ac([]() -> e {}()) {} + o *ae(int *ap, int *aq, int *ar, int *as) { an(ap, aq, ar, as, this); } +}; +template +an::an(int *, int *aq, int *ar, int *as, ac *au) : o(aq, ar, as, au) { + p().n(); +} +void av() { new q; } -- 2.11.4.GIT