From patchwork Fri Dec 2 01:33:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 701777 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tVGsW1q0tz9t0G for ; Fri, 2 Dec 2016 12:34:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DZrcnoJo"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=b5rZVwDjdko0qJ326B2PDhNJkGBqfiyVAgz7FER1R+a 41ouRNWWi5ycq53e9OB5Q0tx57GX49RBmQXbGKEh28OhqlMregz43IOg60P2YOAs GEjNws7eC8PsLrAifG8ReUMAEAVRod3U1vMKRC+uvWnratsv7blsTjjwr1gtEO3M = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=+pJTuHOK5/mui8arZ1vX+8dP43s=; b=DZrcnoJogUQdOPm2A aLMCpP5QRHyASH/chd6reil37F7QfTtklu4o3DOOdGsHJlPWyNu5Un7Sz6Z/UZCE +hCV2B0ajWmZRUvIb+E6AInAZ6YAypSptRqud+MOh9t2gYAR2eu1LTW+3R3rPdEK 7zjyqIxZLgNrrQon8p5k+sCOoA= Received: (qmail 107397 invoked by alias); 2 Dec 2016 01:34:11 -0000 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 Received: (qmail 107328 invoked by uid 89); 2 Dec 2016 01:34:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=1345, expr_op, UD:esym, sk:value.f X-Spam-User: qpsmtpd, 2 recipients X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Dec 2016 01:33:57 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id uB21XtwD042126 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 1 Dec 2016 17:33:55 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id uB21XsRM042125; Thu, 1 Dec 2016 17:33:54 -0800 (PST) (envelope-from sgk) Date: Thu, 1 Dec 2016 17:33:54 -0800 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/78618 -- RANK() should not ICE Message-ID: <20161202013354.GA42106@troutmask.apl.washington.edu> Reply-To: kargl@uw.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.1 (2016-04-27) The attached patch fixes an ICE, a nearby whitespace issue, and removed the ATTRIBUTE_UNUSED tag. THe change has passed regression testing on x86_64-*-freebsd. Ok to commit? 2016-12-01 Steven G. Kargl PR fortran/78618 * check.c (gfc_check_rank): Remove ATTRIBUTE_UNUSED. Fix whitespace. Fix ICE where a NULL pointer is dereferenced. * simplify.c (gfc_convert_char_constant): Do not buffer error. 2016-12-01 Steven G. Kargl PR fortran/78618 * gfortran.dg/char_conversion.f90: New test. Index: gcc/fortran/check.c =================================================================== --- gcc/fortran/check.c (revision 243142) +++ gcc/fortran/check.c (working copy) @@ -3667,7 +3667,7 @@ gfc_check_range (gfc_expr *x) bool -gfc_check_rank (gfc_expr *a ATTRIBUTE_UNUSED) +gfc_check_rank (gfc_expr *a) { /* Any data object is allowed; a "data object" is a "constant (4.1.3), variable (6), or subobject of a constant (2.4.3.2.3)" (F2008, 1.3.45). */ @@ -3676,9 +3676,16 @@ gfc_check_rank (gfc_expr *a ATTRIBUTE_UN /* Functions returning pointers are regarded as variable, cf. F2008, R602. */ if (a->expr_type == EXPR_FUNCTION) - is_variable = a->value.function.esym - ? a->value.function.esym->result->attr.pointer - : a->symtree->n.sym->result->attr.pointer; + { + if (a->value.function.esym) + is_variable = a->value.function.esym->result->attr.pointer; + else if (a->symtree->n.sym->result) + is_variable = a->symtree->n.sym->result->attr.pointer; + else if (a->symtree->n.sym->value) + is_variable = true; + else + gfc_internal_error ("gfc_check_rank(): invalid function result"); + } if (a->expr_type == EXPR_OP || a->expr_type == EXPR_NULL || a->expr_type == EXPR_COMPCALL|| a->expr_type == EXPR_PPC Index: gcc/fortran/simplify.c =================================================================== --- gcc/fortran/simplify.c (revision 243142) +++ gcc/fortran/simplify.c (working copy) @@ -7148,7 +7148,7 @@ gfc_convert_char_constant (gfc_expr *e, if (!gfc_check_character_range (result->value.character.string[i], kind)) { - gfc_error ("Character %qs in string at %L cannot be converted " + gfc_error_now ("Character %qs in string at %L cannot be converted " "into character kind %d", gfc_print_wide_char (result->value.character.string[i]), &e->where, kind); Index: gcc/testsuite/gfortran.dg/char_conversion.f90 =================================================================== --- gcc/testsuite/gfortran.dg/char_conversion.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/char_conversion.f90 (working copy) @@ -0,0 +1,6 @@ +! { dg-do compile } +! PR fortran/78618 +program p + character, parameter :: c = char(256,4) ! { dg-error "cannot be converted" } + if (rank(c) /= 0) call abort +end