From ba3815157cb8d15f2726090248bbfee4e038104e Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 20 Dec 2013 13:16:35 -0500
Subject: [PATCH 71/88] Concretize gimple_cond_{true|false}_label

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/gimple.h   |  7 +++----
 gcc/omp-low.c  |  5 +++--
 gcc/tree-cfg.c | 43 ++++++++++++++++++++++++++-----------------
 gcc/tree-eh.c  | 17 +++++++++++------
 4 files changed, 43 insertions(+), 29 deletions(-)

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 6f7b86b..af6668d 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;
-- 
1.8.5.3

