From patchwork Wed Jul 14 23:01:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Emit default CASE_LABEL_EXPR for character CASE DEFAULT (PR fortran/40206) From: Jakub Jelinek X-Patchwork-Id: 58939 Message-Id: <20100714230119.GM20208@tyan-ft48-01.lab.bos.redhat.com> To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Date: Thu, 15 Jul 2010 01:01:19 +0200 Hi! This patch emits the default case (CASE_LABEL_EXPR with both low and high NULL) for the default case if any. Also, it doesn't emit all other CASE_LABEL_EXPRs as case 1 ... 1:;, instead emits them as case 1:;. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-07-15 Jakub Jelinek PR fortran/40206 * trans-stmt.c (gfc_trans_character_select): Always use NULL for high in CASE_LABEL_EXPR and use NULL for low for the default case. * gfortran.dg/select_char_3.f90: New test. Jakub --- gcc/fortran/trans-stmt.c 2010-07-14 22:36:16.000000000 +0200 +++ gcc/fortran/trans-stmt.c 2010-07-14 22:21:29.000000000 +0200 @@ -1806,8 +1806,9 @@ { label = gfc_build_label_decl (NULL_TREE); tmp = fold_build3 (CASE_LABEL_EXPR, void_type_node, - build_int_cst (NULL_TREE, d->n), - build_int_cst (NULL_TREE, d->n), label); + (d->low == NULL && d->high == NULL) + ? NULL : build_int_cst (NULL_TREE, d->n), + NULL, label); gfc_add_expr_to_block (&body, tmp); } --- gcc/testsuite/gfortran.dg/select_char_3.f90.jj 2010-07-14 22:40:59.000000000 +0200 +++ gcc/testsuite/gfortran.dg/select_char_3.f90 2010-07-14 22:33:33.000000000 +0200 @@ -0,0 +1,15 @@ +! PR fortran/40206 +! { dg-do compile } +! { dg-options "-O2 -Wuninitialized" } + +function char2type (char) + character, intent(in) :: char + integer :: char2type + + select case (char) + case ('E','e') + char2type=1 + case default + char2type=-1234 + end select +end function