From 0f62c7a0cc5b2da41f98c338185dbf036ad468ff Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 16 Nov 2015 20:16:57 +0000 Subject: [PATCH] re PR c++/68362 (ICE: tree check: expected integer_cst, have nop_expr in get_val, at tree.h:5157) PR c++/68362 * c-common.c (check_case_bounds): Fold low and high cases. * g++.dg/delayedfold/switch-1.C: New test. From-SVN: r230435 --- gcc/c-family/ChangeLog | 5 +++++ gcc/c-family/c-common.c | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/delayedfold/switch-1.C | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/delayedfold/switch-1.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index e9851aa6ddd..3151e343a1d 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2015-11-16 Marek Polacek + + PR c++/68362 + * c-common.c (check_case_bounds): Fold low and high cases. + 2015-11-16 Marek Polacek * c-ada-spec.c (dump_ada_template): Use RECORD_OR_UNION_TYPE_P. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index a062f81a1c3..06d857cc970 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -3769,6 +3769,10 @@ check_case_bounds (location_t loc, tree type, tree orig_type, min_value = TYPE_MIN_VALUE (orig_type); max_value = TYPE_MAX_VALUE (orig_type); + /* We'll really need integer constants here. */ + case_low = fold (case_low); + case_high = fold (case_high); + /* Case label is less than minimum for type. */ if (tree_int_cst_compare (case_low, min_value) < 0 && tree_int_cst_compare (case_high, min_value) < 0) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ac40be92d9d..0f6a593c445 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-16 Marek Polacek + + PR c++/68362 + * g++.dg/delayedfold/switch-1.C: New test. + 2015-11-16 Steven G. Kargl PR fortran/58027 diff --git a/gcc/testsuite/g++.dg/delayedfold/switch-1.C b/gcc/testsuite/g++.dg/delayedfold/switch-1.C new file mode 100644 index 00000000000..302da2365d1 --- /dev/null +++ b/gcc/testsuite/g++.dg/delayedfold/switch-1.C @@ -0,0 +1,19 @@ +// PR c++/68362 +// { dg-do compile { target c++11 } } + +enum class A { foo }; +enum E { bar }; + +void +fn1 (const A a) +{ + switch (a) + case A::foo:; +} + +void +fn2 (E e) +{ + switch (e) + case bar:; +} -- 2.30.2