diff mbox

[gimple-classes,committed,71/92] Concretize gimple_cond_{true|false}_label

Message ID 1414442490-14841-72-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Oct. 27, 2014, 8:41 p.m. UTC
This corresponds to:
  [PATCH 73/89] Concretize gimple_cond_{true|false}_label
  https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01169.html
from the original 89-patch kit

That earlier patch was approved by Jeff:
> OK once prerequisites have gone in.
in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00845.html

gcc/
	* gimple.h (gimple_cond_true_label): Require a const_gimple_cond
	rather than just a const_gimple.
	(gimple_cond_false_label): Likewise.

	* omp-low.c (diagnose_sb_2): Add checked cast to gimple_cond within
	case GIMPLE_COND.
	* tree-eh.c (maybe_record_in_goto_queue): Likewise.

	* tree-cfg.c (verify_gimple_stmt): Add a checked cast to gimple_cond
	within "case GIMPLE_COND", splitting it out into...
	(verify_gimple_label): New.
---
 gcc/ChangeLog.gimple-classes | 16 ++++++++++++++++
 gcc/gimple.h                 |  7 +++----
 gcc/omp-low.c                |  5 +++--
 gcc/tree-cfg.c               | 43 ++++++++++++++++++++++++++-----------------
 gcc/tree-eh.c                | 17 +++++++++++------
 5 files changed, 59 insertions(+), 29 deletions(-)
diff mbox

Patch

diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes
index aa83c24..2bff31c 100644
--- a/gcc/ChangeLog.gimple-classes
+++ b/gcc/ChangeLog.gimple-classes
@@ -1,5 +1,21 @@ 
 2014-10-24  David Malcolm  <dmalcolm@redhat.com>
 
+	Concretize gimple_cond_{true|false}_label
+
+	* gimple.h (gimple_cond_true_label): Require a const_gimple_cond
+	rather than just a const_gimple.
+	(gimple_cond_false_label): Likewise.
+
+	* omp-low.c (diagnose_sb_2): Add checked cast to gimple_cond within
+	case GIMPLE_COND.
+	* tree-eh.c (maybe_record_in_goto_queue): Likewise.
+
+	* tree-cfg.c (verify_gimple_stmt): Add a checked cast to gimple_cond
+	within "case GIMPLE_COND", splitting it out into...
+	(verify_gimple_label): New.
+
+2014-10-24  David Malcolm  <dmalcolm@redhat.com>
+
 	Concretize gimple_switch_index and gimple_switch_index_ptr
 
 	* gimple.h (gimple_switch_index): Require a const_gimple_switch rather
diff --git a/gcc/gimple.h b/gcc/gimple.h
index dc080de..94f3416 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -3080,9 +3080,8 @@  gimple_cond_set_rhs (gimple gs, tree rhs)
    predicate evaluates to true.  */
 
 static inline tree
-gimple_cond_true_label (const_gimple gs)
+gimple_cond_true_label (const_gimple_cond gs)
 {
-  GIMPLE_CHECK (gs, GIMPLE_COND);
   return gimple_op (gs, 2);
 }
 
@@ -3111,9 +3110,9 @@  gimple_cond_set_false_label (gimple_cond gs, tree label)
    predicate evaluates to false.  */
 
 static inline tree
-gimple_cond_false_label (const_gimple gs)
+gimple_cond_false_label (const_gimple_cond gs)
 {
-  GIMPLE_CHECK (gs, GIMPLE_COND);
+
   return gimple_op (gs, 3);
 }
 
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index be4037b..2ab49c3 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -10919,7 +10919,8 @@  diagnose_sb_2 (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
 
     case GIMPLE_COND:
 	{
-	  tree lab = gimple_cond_true_label (stmt);
+	  gimple_cond cond_stmt = as_a <gimple_cond> (stmt);
+	  tree lab = gimple_cond_true_label (cond_stmt);
 	  if (lab)
 	    {
 	      n = splay_tree_lookup (all_labels,
@@ -10927,7 +10928,7 @@  diagnose_sb_2 (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
 	      diagnose_sb_0 (gsi_p, context,
 			     n ? (gimple) n->value : NULL);
 	    }
-	  lab = gimple_cond_false_label (stmt);
+	  lab = gimple_cond_false_label (cond_stmt);
 	  if (lab)
 	    {
 	      n = splay_tree_lookup (all_labels,
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index f17b342..ad530f3 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -4482,6 +4482,31 @@  verify_gimple_label (gimple_label stmt)
   return err;
 }
 
+/* Verify a gimple cond statement STMT.
+   Returns true if anything is wrong.  */
+
+static bool
+verify_gimple_cond (gimple_cond stmt)
+{
+  if (TREE_CODE_CLASS (gimple_cond_code (stmt)) != tcc_comparison)
+    {
+      error ("invalid comparison code in gimple cond");
+      return true;
+    }
+  if (!(!gimple_cond_true_label (stmt)
+	|| TREE_CODE (gimple_cond_true_label (stmt)) == LABEL_DECL)
+      || !(!gimple_cond_false_label (stmt)
+	   || TREE_CODE (gimple_cond_false_label (stmt)) == LABEL_DECL))
+    {
+      error ("invalid labels in gimple cond");
+      return true;
+    }
+
+  return verify_gimple_comparison (boolean_type_node,
+				   gimple_cond_lhs (stmt),
+				   gimple_cond_rhs (stmt));
+}
+
 /* Verify the GIMPLE statement STMT.  Returns true if there is an
    error, otherwise false.  */
 
@@ -4500,23 +4525,7 @@  verify_gimple_stmt (gimple stmt)
       return verify_gimple_call (as_a <gimple_call> (stmt));
 
     case GIMPLE_COND:
-      if (TREE_CODE_CLASS (gimple_cond_code (stmt)) != tcc_comparison)
-	{
-	  error ("invalid comparison code in gimple cond");
-	  return true;
-	}
-      if (!(!gimple_cond_true_label (stmt)
-	    || TREE_CODE (gimple_cond_true_label (stmt)) == LABEL_DECL)
-	  || !(!gimple_cond_false_label (stmt)
-	       || TREE_CODE (gimple_cond_false_label (stmt)) == LABEL_DECL))
-	{
-	  error ("invalid labels in gimple cond");
-	  return true;
-	}
-	  
-      return verify_gimple_comparison (boolean_type_node,
-				       gimple_cond_lhs (stmt),
-				       gimple_cond_rhs (stmt));
+      return verify_gimple_cond (as_a <gimple_cond> (stmt));
 
     case GIMPLE_GOTO:
       return verify_gimple_goto (as_a <gimple_goto> (stmt));
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index da54772..2ef68c9 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -671,12 +671,17 @@  maybe_record_in_goto_queue (struct leh_state *state, gimple stmt)
   switch (gimple_code (stmt))
     {
     case GIMPLE_COND:
-      new_stmt.tp = gimple_op_ptr (stmt, 2);
-      record_in_goto_queue_label (tf, new_stmt, gimple_cond_true_label (stmt),
-				  EXPR_LOCATION (*new_stmt.tp));
-      new_stmt.tp = gimple_op_ptr (stmt, 3);
-      record_in_goto_queue_label (tf, new_stmt, gimple_cond_false_label (stmt),
-				  EXPR_LOCATION (*new_stmt.tp));
+      {
+	gimple_cond cond_stmt = as_a <gimple_cond> (stmt);
+	new_stmt.tp = gimple_op_ptr (cond_stmt, 2);
+	record_in_goto_queue_label (tf, new_stmt,
+				    gimple_cond_true_label (cond_stmt),
+				    EXPR_LOCATION (*new_stmt.tp));
+	new_stmt.tp = gimple_op_ptr (cond_stmt, 3);
+	record_in_goto_queue_label (tf, new_stmt,
+				    gimple_cond_false_label (cond_stmt),
+				    EXPR_LOCATION (*new_stmt.tp));
+      }
       break;
     case GIMPLE_GOTO:
       new_stmt.g = stmt;