From c0d8214cfc1742e2ccf99c86b917a5f231546744 Mon Sep 17 00:00:00 2001
From: pault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 19 Sep 2006 11:04:55 +0000
Subject: [PATCH] 2006-09-19 Paul Thomas <pault@gcc.gnu.org> 	   Steven
 Bosscher  <steven@gcc.gnu.org>

	PR fortran/29101
	* trans-stmt.c (gfc_trans_character_select): Store the label
	from select_string and then clean up any temporaries from the
	conversion of the select expression, before branching to the
	selected case.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117053 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/fortran/ChangeLog    |  9 +++++++++
 gcc/fortran/trans-stmt.c | 10 +++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 44e1800a1440..4a620fdc4139 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,12 @@
+2006-09-19 Paul Thomas <pault@gcc.gnu.org>
+	   Steven Bosscher  <steven@gcc.gnu.org>
+
+	PR fortran/29101
+	* trans-stmt.c (gfc_trans_character_select): Store the label
+	from select_string and then clean up any temporaries from the
+	conversion of the select expression, before branching to the
+	selected case.
+
 2006-09-18 Paul Thomas <pault@gcc.gnu.org>
 
 	PR fortran/28526
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 841b45782036..e4cb94fff842 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -1307,6 +1307,7 @@ static tree
 gfc_trans_character_select (gfc_code *code)
 {
   tree init, node, end_label, tmp, type, args, *labels;
+  tree case_label;
   stmtblock_t block, body;
   gfc_case *cp, *d;
   gfc_code *c;
@@ -1464,7 +1465,12 @@ gfc_trans_character_select (gfc_code *code)
   gfc_add_block_to_block (&block, &se.pre);
 
   tmp = build_function_call_expr (gfor_fndecl_select_string, args);
-  tmp = build1 (GOTO_EXPR, void_type_node, tmp);
+  case_label = gfc_create_var (TREE_TYPE (tmp), "case_label");
+  gfc_add_modify_expr (&block, case_label, tmp);
+
+  gfc_add_block_to_block (&block, &se.post);
+
+  tmp = build1 (GOTO_EXPR, void_type_node, case_label);
   gfc_add_expr_to_block (&block, tmp);
 
   tmp = gfc_finish_block (&body);
@@ -1475,8 +1481,6 @@ gfc_trans_character_select (gfc_code *code)
   if (n != 0)
     gfc_free (labels);
 
-  gfc_add_block_to_block (&block, &se.post);
-
   return gfc_finish_block (&block);
 }
 
-- 
GitLab