This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix tree checking for SWITCH_STMT vs. SWITCH_EXPR (and a few others)


Hi,

While playing with a patch for PR18133 I noticed we were trying
to take the SWITCH_COND of a GOTO_EXPR.  Uhm, right.

The fix is a bit more involved than I had expected at first.  The
accessor macros of SWITCH_EXPR are overloaded by the C and C++
front ends for SWITCH_STMT.  So I had to give them each their own
set of accessor macros.

I also noticed a few other missing tree checks.

Bootstrapped and tested on x86_64-suse-linux-gnu.  OK for mainline?

Gr.
Steven


	* tree.h (SWITCH_COND, SWITCH_BODY, SWITCH_LABELS, CASE_LOW,
	CASE_HIGH, CASE_LABEL, ASM_STRING, ASM_OUTPUTS, ASM_INPUTS,
	ASM_CLOBBERS): Add tree checks.

	* c-common.h (SWITCH_TYPE): Rename to SWITCH_STMT_TYPE.
	(SWITCH_STMT_COND, SWITCH_STMT_BODY): New.
	* c-common.def (SWITCH_STMT): Update to match.
	* c-common.c (c_do_switch_warnings): Use SWITCH_STMT accessor
	macros instead of SWITCH_EXPR ones.
	* c-dump.c (c_dump_tree): Likewise.
	* c-gimplify.c (gimplify_switch_stmt): Likewise.
	* c-typeck.c (c_start_case, do_case, c_finish_case): Likewise.

cp/
	* decl.c (finish_case_label): Use SWITCH_STMT accessor macros
	instead of SWITCH_EXPR ones.
	* pt.c (tsubst_expr): Likewise.
	* semantics.c (begin_switch_stmt, finish_switch_cond,
	finish_switch_stmt): Likewise.

doc/
	* c-tree.texi (SWITCH_STMT): Update accessor macro names.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.600
diff -u -3 -p -r1.600 c-common.c
--- c-common.c	23 Jan 2005 19:15:33 -0000	1.600
+++ c-common.c	26 Jan 2005 21:24:57 -0000
@@ -3676,7 +3676,7 @@ c_do_switch_warnings (splay_tree cases, 
   else
     switch_location = input_location;
 
-  type = SWITCH_TYPE (switch_stmt);
+  type = SWITCH_STMT_TYPE (switch_stmt);
 
   default_node = splay_tree_lookup (cases, (splay_tree_key) NULL);
   if (warn_switch_default && !default_node)
@@ -3688,7 +3688,7 @@ c_do_switch_warnings (splay_tree cases, 
      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_COND (switch_stmt)) != INTEGER_CST)
+      && TREE_CODE (SWITCH_STMT_COND (switch_stmt)) != INTEGER_CST)
     {
       tree chain;
 
Index: c-common.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.def,v
retrieving revision 1.24
diff -u -3 -p -r1.24 c-common.def
--- c-common.def	17 Sep 2004 21:54:21 -0000	1.24
+++ c-common.def	26 Jan 2005 21:24:57 -0000
@@ -52,7 +52,7 @@ DEFTREECODE (BREAK_STMT, "break_stmt", t
 DEFTREECODE (CONTINUE_STMT, "continue_stmt", tcc_expression, 0)
 
 /* Used to represent a 'switch' statement. The operands are
-   SWITCH_COND, SWITCH_BODY and SWITCH_TYPE, respectively.  */
+   SWITCH_STMT_COND, SWITCH_STMT_BODY and SWITCH_STMT_TYPE, respectively.  */
 DEFTREECODE (SWITCH_STMT, "switch_stmt", tcc_expression, 3)
 
 /* A STMT_EXPR represents a statement-expression.  The
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.275
diff -u -3 -p -r1.275 c-common.h
--- c-common.h	23 Jan 2005 19:15:34 -0000	1.275
+++ c-common.h	26 Jan 2005 21:24:57 -0000
@@ -733,7 +733,9 @@ extern void finish_file	(void);
 #define FOR_EXPR(NODE)          TREE_OPERAND (FOR_STMT_CHECK (NODE), 2)
 #define FOR_BODY(NODE)          TREE_OPERAND (FOR_STMT_CHECK (NODE), 3)
 
-#define SWITCH_TYPE(NODE)	TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 2)
+#define SWITCH_STMT_COND(NODE)	TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 0)
+#define SWITCH_STMT_BODY(NODE)	TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 1)
+#define SWITCH_STMT_TYPE(NODE)	TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 2)
 
 /* STMT_EXPR accessor.  */
 #define STMT_EXPR_STMT(NODE)    TREE_OPERAND (STMT_EXPR_CHECK (NODE), 0)
Index: c-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-dump.c,v
retrieving revision 1.27
diff -u -3 -p -r1.27 c-dump.c
--- c-dump.c	30 Jun 2004 18:05:03 -0000	1.27
+++ c-dump.c	26 Jan 2005 21:24:57 -0000
@@ -80,8 +80,8 @@ c_dump_tree (void *dump_info, tree t)
 
     case SWITCH_STMT:
       dump_stmt (di, t);
-      dump_child ("cond", SWITCH_COND (t));
-      dump_child ("body", SWITCH_BODY (t));
+      dump_child ("cond", SWITCH_STMT_COND (t));
+      dump_child ("body", SWITCH_STMT_BODY (t));
       break;
 
     case WHILE_STMT:
Index: c-gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-gimplify.c,v
retrieving revision 2.24
diff -u -3 -p -r2.24 c-gimplify.c
--- c-gimplify.c	6 Dec 2004 17:24:16 -0000	2.24
+++ c-gimplify.c	26 Jan 2005 21:24:57 -0000
@@ -454,12 +454,12 @@ gimplify_switch_stmt (tree *stmt_p)
 
   break_block = begin_bc_block (bc_break);
 
-  body = SWITCH_BODY (stmt);
+  body = SWITCH_STMT_BODY (stmt);
   if (!body)
     body = build_empty_stmt ();
 
-  *stmt_p = build3 (SWITCH_EXPR, SWITCH_TYPE (stmt), SWITCH_COND (stmt),
-		    body, NULL_TREE);
+  *stmt_p = build3 (SWITCH_EXPR, SWITCH_STMT_TYPE (stmt),
+		    SWITCH_STMT_COND (stmt), body, NULL_TREE);
   SET_EXPR_LOCATION (*stmt_p, stmt_locus);
   gimplify_stmt (stmt_p);
 
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.413
diff -u -3 -p -r1.413 c-typeck.c
--- c-typeck.c	22 Jan 2005 00:12:07 -0000	1.413
+++ c-typeck.c	26 Jan 2005 21:24:58 -0000
@@ -6563,8 +6563,7 @@ c_start_case (tree exp)
 
   /* Add this new SWITCH_STMT to the stack.  */
   cs = XNEW (struct c_switch);
-  cs->switch_stmt = build_stmt ((enum tree_code) SWITCH_STMT, exp, NULL_TREE,
-				orig_type);
+  cs->switch_stmt = build_stmt (SWITCH_STMT, exp, NULL_TREE, orig_type);
   cs->orig_type = orig_type;
   cs->cases = splay_tree_new (case_compare, NULL, NULL);
   cs->next = c_switch_stack;
@@ -6583,7 +6582,7 @@ do_case (tree low_value, tree high_value
   if (c_switch_stack)
     {
       label = c_add_case_label (c_switch_stack->cases,
-				SWITCH_COND (c_switch_stack->switch_stmt),
+				SWITCH_STMT_COND (c_switch_stack->switch_stmt),
 				c_switch_stack->orig_type,
 				low_value, high_value);
       if (label == error_mark_node)
@@ -6604,7 +6603,7 @@ c_finish_case (tree body)
 {
   struct c_switch *cs = c_switch_stack;
 
-  SWITCH_BODY (cs->switch_stmt) = body;
+  SWITCH_STMT_BODY (cs->switch_stmt) = body;
 
   /* Emit warnings as needed.  */
   c_do_switch_warnings (cs->cases, cs->switch_stmt);
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.681
diff -u -3 -p -r1.681 tree.h
--- tree.h	26 Jan 2005 15:20:51 -0000	1.681
+++ tree.h	26 Jan 2005 21:24:58 -0000
@@ -1227,15 +1227,15 @@ struct tree_vec GTY(())
 /* SWITCH_EXPR accessors. These give access to the condition, body and
    original condition type (before any compiler conversions)
    of the switch statement, respectively.  */
-#define SWITCH_COND(NODE)       TREE_OPERAND ((NODE), 0)
-#define SWITCH_BODY(NODE)       TREE_OPERAND ((NODE), 1)
-#define SWITCH_LABELS(NODE)     TREE_OPERAND ((NODE), 2)
+#define SWITCH_COND(NODE)       TREE_OPERAND (SWITCH_EXPR_CHECK (NODE), 0)
+#define SWITCH_BODY(NODE)       TREE_OPERAND (SWITCH_EXPR_CHECK (NODE), 1)
+#define SWITCH_LABELS(NODE)     TREE_OPERAND (SWITCH_EXPR_CHECK (NODE), 2)
 
 /* CASE_LABEL_EXPR accessors. These give access to the high and low values
    of a case label, respectively.  */
-#define CASE_LOW(NODE)          	TREE_OPERAND ((NODE), 0)
-#define CASE_HIGH(NODE)         	TREE_OPERAND ((NODE), 1)
-#define CASE_LABEL(NODE)		TREE_OPERAND ((NODE), 2)
+#define CASE_LOW(NODE)          	TREE_OPERAND (CASE_LABEL_EXPR_CHECK (NODE), 0)
+#define CASE_HIGH(NODE)         	TREE_OPERAND (CASE_LABEL_EXPR_CHECK (NODE), 1)
+#define CASE_LABEL(NODE)		TREE_OPERAND (CASE_LABEL_EXPR_CHECK (NODE), 2)
 
 /* The operands of a BIND_EXPR.  */
 #define BIND_EXPR_VARS(NODE) (TREE_OPERAND (BIND_EXPR_CHECK (NODE), 0))
@@ -1250,10 +1250,10 @@ struct tree_vec GTY(())
    instruction (e.g., "mov x, y"). ASM_OUTPUTS, ASM_INPUTS, and
    ASM_CLOBBERS represent the outputs, inputs, and clobbers for the
    statement.  */
-#define ASM_STRING(NODE)        TREE_OPERAND ((NODE), 0)
-#define ASM_OUTPUTS(NODE)       TREE_OPERAND ((NODE), 1)
-#define ASM_INPUTS(NODE)        TREE_OPERAND ((NODE), 2)
-#define ASM_CLOBBERS(NODE)      TREE_OPERAND ((NODE), 3)
+#define ASM_STRING(NODE)        TREE_OPERAND (ASM_EXPR_CHECK (NODE), 0)
+#define ASM_OUTPUTS(NODE)       TREE_OPERAND (ASM_EXPR_CHECK (NODE), 1)
+#define ASM_INPUTS(NODE)        TREE_OPERAND (ASM_EXPR_CHECK (NODE), 2)
+#define ASM_CLOBBERS(NODE)      TREE_OPERAND (ASM_EXPR_CHECK (NODE), 3)
 /* Nonzero if we want to create an ASM_INPUT instead of an
    ASM_OPERAND with no operands.  */
 #define ASM_INPUT_P(NODE) (TREE_STATIC (NODE))
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1354
diff -u -3 -p -r1.1354 decl.c
--- cp/decl.c	18 Jan 2005 23:49:35 -0000	1.1354
+++ cp/decl.c	26 Jan 2005 21:25:00 -0000
@@ -2383,7 +2383,7 @@ finish_case_label (tree low_value, tree 
     }
 
   /* Find the condition on which this switch statement depends.  */
-  cond = SWITCH_COND (switch_stack->switch_stmt);
+  cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
   if (cond && TREE_CODE (cond) == TREE_LIST)
     cond = TREE_VALUE (cond);
 
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.968
diff -u -3 -p -r1.968 pt.c
--- cp/pt.c	21 Jan 2005 02:27:09 -0000	1.968
+++ cp/pt.c	26 Jan 2005 21:25:01 -0000
@@ -8192,9 +8192,9 @@ tsubst_expr (tree t, tree args, tsubst_f
 
     case SWITCH_STMT:
       stmt = begin_switch_stmt ();
-      tmp = tsubst_expr (SWITCH_COND (t), args, complain, in_decl);
+      tmp = tsubst_expr (SWITCH_STMT_COND (t), args, complain, in_decl);
       finish_switch_cond (tmp, stmt);
-      tsubst_expr (SWITCH_BODY (t), args, complain, in_decl);
+      tsubst_expr (SWITCH_STMT_BODY (t), args, complain, in_decl);
       finish_switch_stmt (stmt);
       break;
 
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.457
diff -u -3 -p -r1.457 semantics.c
--- cp/semantics.c	19 Jan 2005 14:30:21 -0000	1.457
+++ cp/semantics.c	26 Jan 2005 21:25:01 -0000
@@ -858,7 +858,7 @@ begin_switch_stmt (void)
 
   scope = do_pushlevel (sk_block);
   TREE_CHAIN (r) = scope;
-  begin_cond (&SWITCH_COND (r));
+  begin_cond (&SWITCH_STMT_COND (r));
 
   return r;
 }
@@ -902,11 +902,11 @@ finish_switch_cond (tree cond, tree swit
 	    cond = index;
 	}
     }
-  finish_cond (&SWITCH_COND (switch_stmt), cond);
-  SWITCH_TYPE (switch_stmt) = orig_type;
+  finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
+  SWITCH_STMT_TYPE (switch_stmt) = orig_type;
   add_stmt (switch_stmt);
   push_switch (switch_stmt);
-  SWITCH_BODY (switch_stmt) = push_stmt_list ();
+  SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
 }
 
 /* Finish the body of a switch-statement, which may be given by
@@ -917,7 +917,8 @@ finish_switch_stmt (tree switch_stmt)
 {
   tree scope;
 
-  SWITCH_BODY (switch_stmt) = pop_stmt_list (SWITCH_BODY (switch_stmt));
+  SWITCH_STMT_BODY (switch_stmt) =
+    pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
   pop_switch (); 
   finish_stmt ();
 
Index: doc/c-tree.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/c-tree.texi,v
retrieving revision 1.69
diff -u -3 -p -r1.69 c-tree.texi
--- doc/c-tree.texi	16 Dec 2004 14:17:24 -0000	1.69
+++ doc/c-tree.texi	26 Jan 2005 21:25:02 -0000
@@ -1573,11 +1573,11 @@ cleanups must be executed in the reverse
 
 @item SWITCH_STMT
 
-Used to represent a @code{switch} statement.  The @code{SWITCH_COND} is
-the expression on which the switch is occurring.  See the documentation
+Used to represent a @code{switch} statement.  The @code{SWITCH_STMT_COND}
+is the expression on which the switch is occurring.  See the documentation
 for an @code{IF_STMT} for more information on the representation used
-for the condition.  The @code{SWITCH_BODY} is the body of the switch
-statement.   The @code{SWITCH_TYPE} is the original type of switch
+for the condition.  The @code{SWITCH_STMT_BODY} is the body of the switch
+statement.   The @code{SWITCH_STMT_TYPE} is the original type of switch
 expression as given in the source, before any compiler conversions.
 
 @item TRY_BLOCK


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]