From d2c450f009804c99f400ac7f466de063b95ddd1f Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 16 Dec 2013 12:37:56 -0500
Subject: [PATCH 25/88] Introduce gimple_eh_must_not_throw

gcc/
	* coretypes.h (gimple_eh_must_not_throw): New typedef.
	(const_gimple_eh_must_not_throw): New typedef.

	* gimple-pretty-print.c (dump_gimple_eh_must_not_throw): Require
	a gimple_eh_must_not_throw rather than a plain gimple.
	(pp_gimple_stmt_1): Add a checked cast to gimple_eh_must_not_throw
	within GIMPLE_EH_MUST_NOT_THROW case of switch statement.

	* gimple-streamer-in.c (input_gimple_stmt): Likewise.

	* gimple-streamer-out.c (output_gimple_stmt): Likewise.

	* gimple.c (gimple_build_eh_must_not_throw): Return a
	gimple_eh_must_not_throw rather than a plain gimple.

	* gimple.h (gimple_build_eh_must_not_throw): Return a
	gimple_eh_must_not_throw rather than a plain gimple.
	(gimple_eh_must_not_throw_fndecl): Require a
	gimple_eh_must_not_throw rather than a plain gimple.
	(gimple_eh_must_not_throw_set_fndecl): Likewise.

	* tree-eh.c (lower_eh_must_not_throw): Add checked cast.
---
 gcc/coretypes.h           | 4 ++++
 gcc/gimple-pretty-print.c | 8 +++++---
 gcc/gimple-streamer-in.c  | 4 +++-
 gcc/gimple-streamer-out.c | 5 ++++-
 gcc/gimple.c              | 6 ++++--
 gcc/gimple.h              | 9 ++++-----
 gcc/tree-eh.c             | 3 ++-
 7 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index d2d19ec..51b73f6 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -142,6 +142,10 @@ struct gimple_statement_eh_filter;
 typedef struct gimple_statement_eh_filter *gimple_eh_filter;
 typedef const struct gimple_statement_eh_filter *const_gimple_eh_filter;
 
+struct gimple_statement_eh_mnt;
+typedef struct gimple_statement_eh_mnt *gimple_eh_must_not_throw;
+typedef const struct gimple_statement_eh_mnt *const_gimple_eh_must_not_throw;
+
 struct gimple_statement_phi;
 typedef struct gimple_statement_phi *gimple_phi;
 typedef const struct gimple_statement_phi *const_gimple_phi;
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 3238382..a15c2a3 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1021,8 +1021,8 @@ dump_gimple_eh_filter (pretty_printer *buffer, gimple_eh_filter gs, int spc,
 /* Dump a GIMPLE_EH_MUST_NOT_THROW tuple.  */
 
 static void
-dump_gimple_eh_must_not_throw (pretty_printer *buffer, gimple gs,
-			       int spc, int flags)
+dump_gimple_eh_must_not_throw (pretty_printer *buffer,
+			       gimple_eh_must_not_throw gs, int spc, int flags)
 {
   if (flags & TDF_RAW)
     dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs,
@@ -2229,7 +2229,9 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags)
       break;
 
     case GIMPLE_EH_MUST_NOT_THROW:
-      dump_gimple_eh_must_not_throw (buffer, gs, spc, flags);
+      dump_gimple_eh_must_not_throw (buffer,
+				     as_a <gimple_eh_must_not_throw> (gs),
+				     spc, flags);
       break;
 
     case GIMPLE_EH_ELSE:
diff --git a/gcc/gimple-streamer-in.c b/gcc/gimple-streamer-in.c
index a4130a5..1d1ad27 100644
--- a/gcc/gimple-streamer-in.c
+++ b/gcc/gimple-streamer-in.c
@@ -127,7 +127,9 @@ input_gimple_stmt (struct lto_input_block *ib, struct data_in *data_in,
       break;
 
     case GIMPLE_EH_MUST_NOT_THROW:
-      gimple_eh_must_not_throw_set_fndecl (stmt, stream_read_tree (ib, data_in));
+      gimple_eh_must_not_throw_set_fndecl (
+	as_a <gimple_eh_must_not_throw> (stmt),
+	stream_read_tree (ib, data_in));
       break;
 
     case GIMPLE_EH_DISPATCH:
diff --git a/gcc/gimple-streamer-out.c b/gcc/gimple-streamer-out.c
index cc87e88..41a4dc4 100644
--- a/gcc/gimple-streamer-out.c
+++ b/gcc/gimple-streamer-out.c
@@ -101,7 +101,10 @@ output_gimple_stmt (struct output_block *ob, gimple stmt)
       break;
 
     case GIMPLE_EH_MUST_NOT_THROW:
-      stream_write_tree (ob, gimple_eh_must_not_throw_fndecl (stmt), true);
+      stream_write_tree (ob,
+			 gimple_eh_must_not_throw_fndecl (
+			   as_a <gimple_eh_must_not_throw> (stmt)),
+			 true);
       break;
 
     case GIMPLE_EH_DISPATCH:
diff --git a/gcc/gimple.c b/gcc/gimple.c
index 3b1ff98..a52d989 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -644,10 +644,12 @@ gimple_build_eh_filter (tree types, gimple_seq failure)
 
 /* Build a GIMPLE_EH_MUST_NOT_THROW statement.  */
 
-gimple
+gimple_eh_must_not_throw
 gimple_build_eh_must_not_throw (tree decl)
 {
-  gimple p = gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0);
+  gimple_eh_must_not_throw p =
+    as_a <gimple_eh_must_not_throw> (
+      gimple_alloc (GIMPLE_EH_MUST_NOT_THROW, 0));
 
   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
   gcc_assert (flags_from_decl_or_type (decl) & ECF_NORETURN);
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 0d95035..445a1c0 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -1327,7 +1327,7 @@ gimple_asm gimple_build_asm_vec (const char *, vec<tree, va_gc> *,
 				 vec<tree, va_gc> *);
 gimple_catch gimple_build_catch (tree, gimple_seq);
 gimple_eh_filter gimple_build_eh_filter (tree, gimple_seq);
-gimple gimple_build_eh_must_not_throw (tree);
+gimple_eh_must_not_throw gimple_build_eh_must_not_throw (tree);
 gimple gimple_build_eh_else (gimple_seq, gimple_seq);
 gimple_statement_try *gimple_build_try (gimple_seq, gimple_seq,
 					enum gimple_try_flags);
@@ -3652,18 +3652,17 @@ gimple_eh_filter_set_failure (gimple gs, gimple_seq failure)
 /* Get the function decl to be called by the MUST_NOT_THROW region.  */
 
 static inline tree
-gimple_eh_must_not_throw_fndecl (gimple gs)
+gimple_eh_must_not_throw_fndecl (gimple_eh_must_not_throw eh_mnt_stmt)
 {
-  gimple_statement_eh_mnt *eh_mnt_stmt = as_a <gimple_statement_eh_mnt *> (gs);
   return eh_mnt_stmt->fndecl;
 }
 
 /* Set the function decl to be called by GS to DECL.  */
 
 static inline void
-gimple_eh_must_not_throw_set_fndecl (gimple gs, tree decl)
+gimple_eh_must_not_throw_set_fndecl (gimple_eh_must_not_throw eh_mnt_stmt,
+				     tree decl)
 {
-  gimple_statement_eh_mnt *eh_mnt_stmt = as_a <gimple_statement_eh_mnt *> (gs);
   eh_mnt_stmt->fndecl = decl;
 }
 
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index 15dcf51..d22eb45 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -1861,7 +1861,8 @@ lower_eh_must_not_throw (struct leh_state *state, gimple tp)
 
       this_region = gen_eh_region_must_not_throw (state->cur_region);
       this_region->u.must_not_throw.failure_decl
-	= gimple_eh_must_not_throw_fndecl (inner);
+	= gimple_eh_must_not_throw_fndecl (
+	    as_a <gimple_eh_must_not_throw> (inner));
       this_region->u.must_not_throw.failure_loc
 	= LOCATION_LOCUS (gimple_location (tp));
 
-- 
1.8.5.3

