From patchwork Sun Sep 5 09:45:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 63822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6472EB70FD for ; Sun, 5 Sep 2010 19:45:26 +1000 (EST) Received: (qmail 32244 invoked by alias); 5 Sep 2010 09:45:22 -0000 Received: (qmail 32224 invoked by uid 22791); 5 Sep 2010 09:45:20 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp5.netcologne.de (HELO smtp5.netcologne.de) (194.8.194.25) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 05 Sep 2010 09:45:12 +0000 Received: from [192.168.0.196] (xdsl-78-34-101-150.netcologne.de [78.34.101.150]) by smtp5.netcologne.de (Postfix) with ESMTP id 80C5C40D64B; Sun, 5 Sep 2010 11:45:09 +0200 (CEST) Subject: [patch, fortran] Fix PR 34145, single char detection From: Thomas Koenig To: fortran@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Date: Sun, 05 Sep 2010 11:45:09 +0200 Message-ID: <1283679909.1254.8.camel@linux-fd1f.site> Mime-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello world, the attached patch fixes PR 34145, where we failed to detect that a string was in fact a single character. Regression-tested. OK for trunk? Thomas 2010-09-05 Thomas Koenig PR fortran/34145 * trans-expr.c (gfc_conv_substring): If start and end of the string reference are equal, set the length to one. 2010-09-05 Thomas Koenig PR fortran/34145 * char_length_17.f90: New test. Index: trans-expr.c =================================================================== --- trans-expr.c (Revision 163868) +++ trans-expr.c (Arbeitskopie) @@ -463,12 +463,20 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, in gfc_free (msg); } - tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_charlen_type_node, - end.expr, start.expr); - tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_charlen_type_node, - build_int_cst (gfc_charlen_type_node, 1), tmp); - tmp = fold_build2_loc (input_location, MAX_EXPR, gfc_charlen_type_node, tmp, - build_int_cst (gfc_charlen_type_node, 0)); + /* If the start and end expressions are equal, the length is one. */ + if (ref->u.ss.end + && gfc_dep_compare_expr (ref->u.ss.start, ref->u.ss.end) == 0) + tmp = build_int_cst (gfc_charlen_type_node, 1); + else + { + tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_charlen_type_node, + end.expr, start.expr); + tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_charlen_type_node, + build_int_cst (gfc_charlen_type_node, 1), tmp); + tmp = fold_build2_loc (input_location, MAX_EXPR, gfc_charlen_type_node, + tmp, build_int_cst (gfc_charlen_type_node, 0)); + } + se->string_length = tmp; }