aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c64
1 files changed, 44 insertions, 20 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 5705f4d..817d939 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -3708,32 +3708,17 @@ match_case_to_enum (splay_tree_node node, void *data)
return 0;
}
-/* Handle -Wswitch*. Called from the front end after parsing the switch
- construct. */
-/* ??? Should probably be somewhere generic, since other languages besides
- C and C++ would want this. We'd want to agree on the data structure,
- however, which is a problem. Alternately, we operate on gimplified
- switch_exprs, which I don't especially like. At the moment, however,
- C/C++ are the only tree-ssa languages that support enumerations at all,
- so the point is moot. */
+/* Common code for -Wswitch*. */
-void
-c_do_switch_warnings (splay_tree cases, tree switch_stmt)
+static void
+c_do_switch_warnings_1 (splay_tree cases, location_t switch_location,
+ tree type, tree cond)
{
splay_tree_node default_node;
- location_t switch_location;
- tree type;
if (!warn_switch && !warn_switch_enum && !warn_switch_default)
return;
- if (EXPR_HAS_LOCATION (switch_stmt))
- switch_location = EXPR_LOCATION (switch_stmt);
- else
- switch_location = input_location;
-
- type = SWITCH_STMT_TYPE (switch_stmt);
-
default_node = splay_tree_lookup (cases, (splay_tree_key) NULL);
if (warn_switch_default && !default_node)
warning ("%Hswitch missing default case", &switch_location);
@@ -3744,7 +3729,7 @@ c_do_switch_warnings (splay_tree cases, tree switch_stmt)
default case, or when -Wswitch-enum was specified. */
if (((warn_switch && !default_node) || warn_switch_enum)
&& type && TREE_CODE (type) == ENUMERAL_TYPE
- && TREE_CODE (SWITCH_STMT_COND (switch_stmt)) != INTEGER_CST)
+ && TREE_CODE (cond) != INTEGER_CST)
{
tree chain;
@@ -3788,6 +3773,45 @@ c_do_switch_warnings (splay_tree cases, tree switch_stmt)
}
}
+/* Handle -Wswitch* for a SWITCH_STMT. Called from the front end
+ after parsing the switch construct. */
+/* ??? Should probably be somewhere generic, since other languages besides
+ C and C++ would want this. We'd want to agree on the data structure,
+ however, which is a problem. Alternately, we operate on gimplified
+ switch_exprs, which I don't especially like. At the moment, however,
+ C/C++ are the only tree-ssa languages that support enumerations at all,
+ so the point is moot. */
+
+void
+c_do_switch_warnings (splay_tree cases, tree switch_stmt)
+{
+ location_t switch_location;
+
+ if (EXPR_HAS_LOCATION (switch_stmt))
+ switch_location = EXPR_LOCATION (switch_stmt);
+ else
+ switch_location = input_location;
+ c_do_switch_warnings_1 (cases, switch_location,
+ SWITCH_STMT_TYPE (switch_stmt),
+ SWITCH_STMT_COND (switch_stmt));
+}
+
+/* Like c_do_switch_warnings, but takes a SWITCH_EXPR rather than a
+ SWITCH_STMT. */
+
+void
+c_do_switch_expr_warnings (splay_tree cases, tree switch_expr)
+{
+ location_t switch_location;
+
+ if (EXPR_HAS_LOCATION (switch_expr))
+ switch_location = EXPR_LOCATION (switch_expr);
+ else
+ switch_location = input_location;
+ c_do_switch_warnings_1 (cases, switch_location, TREE_TYPE (switch_expr),
+ SWITCH_COND (switch_expr));
+}
+
/* Finish an expression taking the address of LABEL (an
IDENTIFIER_NODE). Returns an expression for the address. */