aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-04-19 13:56:07 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2019-04-19 13:56:07 +0200
commitc280b7ee5c5dfcc1b4ae2c0389987b7b67ec8cf8 (patch)
treeea24706aa8db720c9a1d2368df12936553d81be8 /gcc/c
parent4180490732498b1d7e30eb73abb6a7c934b89256 (diff)
downloadgcc-c280b7ee5c5dfcc1b4ae2c0389987b7b67ec8cf8.zip
gcc-c280b7ee5c5dfcc1b4ae2c0389987b7b67ec8cf8.tar.gz
gcc-c280b7ee5c5dfcc1b4ae2c0389987b7b67ec8cf8.tar.bz2
re PR c/89888 (When switch controlling expression is promoted from type narrower than int, GCC does not diagnose identical cases)
PR c/89888 * c-common.h (c_add_case_label): Remove orig_type and outside_range_p arguments. (c_do_switch_warnings): Remove outside_range_p argument. * c-common.c (check_case_bounds): Removed. (c_add_case_label): Remove orig_type and outside_range_p arguments. Don't call check_case_bounds. Fold low_value as well as high_value. * c-warn.c (c_do_switch_warnings): Remove outside_range_p argument. Check for case labels outside of range of original type here and adjust them. c/ * c-typeck.c (struct c_switch): Remove outside_range_p member. (c_start_case): Don't clear it. (do_case): Adjust c_add_case_label caller. (c_finish_case): Adjust c_do_switch_warnings caller. cp/ * decl.c (struct cp_switch): Remove outside_range_p member. (push_switch): Don't clear it. (pop_switch): Adjust c_do_switch_warnings caller. (finish_case_label): Adjust c_add_case_label caller. testsuite/ * c-c++-common/pr89888.c: New test. * g++.dg/torture/pr40335.C: Change dg-bogus into dg-warning. Don't expect -Wswitch-unreachable warning. From-SVN: r270455
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c12
2 files changed, 8 insertions, 10 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 27660b9..e5bc2b7 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,5 +1,11 @@
2019-04-19 Jakub Jelinek <jakub@redhat.com>
+ PR c/89888
+ * c-typeck.c (struct c_switch): Remove outside_range_p member.
+ (c_start_case): Don't clear it.
+ (do_case): Adjust c_add_case_label caller.
+ (c_finish_case): Adjust c_do_switch_warnings caller.
+
PR c++/90108
* c-decl.c (merge_decls): If remove is main variant and
DECL_ORIGINAL_TYPE is some other type, remove a DECL_ORIGINAL_TYPE
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 2de4d0f..8286b7d 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -10686,10 +10686,6 @@ struct c_switch {
/* Remember whether the controlling expression had boolean type
before integer promotions for the sake of -Wswitch-bool. */
bool bool_cond_p;
-
- /* Remember whether there was a case value that is outside the
- range of the ORIG_TYPE. */
- bool outside_range_p;
};
/* A stack of the currently active switch statements. The innermost
@@ -10766,7 +10762,6 @@ c_start_case (location_t switch_loc,
cs->cases = splay_tree_new (case_compare, NULL, NULL);
cs->bindings = c_get_switch_bindings ();
cs->bool_cond_p = bool_cond_p;
- cs->outside_range_p = false;
cs->next = c_switch_stack;
c_switch_stack = cs;
@@ -10812,9 +10807,7 @@ do_case (location_t loc, tree low_value, tree high_value)
label = c_add_case_label (loc, c_switch_stack->cases,
SWITCH_COND (c_switch_stack->switch_expr),
- c_switch_stack->orig_type,
- low_value, high_value,
- &c_switch_stack->outside_range_p);
+ low_value, high_value);
if (label == error_mark_node)
label = NULL_TREE;
return label;
@@ -10835,8 +10828,7 @@ c_finish_case (tree body, tree type)
switch_location = EXPR_LOCATION (cs->switch_expr);
c_do_switch_warnings (cs->cases, switch_location,
type ? type : TREE_TYPE (cs->switch_expr),
- SWITCH_COND (cs->switch_expr),
- cs->bool_cond_p, cs->outside_range_p);
+ SWITCH_COND (cs->switch_expr), cs->bool_cond_p);
if (c_switch_covers_all_cases_p (cs->cases, TREE_TYPE (cs->switch_expr)))
SWITCH_ALL_CASES_P (cs->switch_expr) = 1;