From patchwork Thu Oct 1 18:54:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 525271 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 5A4E3140D69 for ; Fri, 2 Oct 2015 04:55:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=VUy1haoY; 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:mime-version:content-type; q=dns; s= default; b=e9PKUWIX5qf5kpYdMX0URsLVX1xhSg+C+5F5wlfmOdTElHniCI0HT s1xSORiXiKnhQJGGNFLacS+h0G+iQw9W7VTjojC6rFU75BMUc0ueLZ3FKmR7Fwjf UwRL2aQh/PDFT6If8lFjhKBBHrttVjJB5s3Ak04r73i43GsPoZvcDA= 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:mime-version:content-type; s= default; bh=saS8lA41jD4QNHwAI0pDuRqKRT8=; b=VUy1haoYGClkQ6gxbm81 4AiTlsNBVsj5UeoYGkv9lt3/SoOfsEqFjVF8NL6BSsWdzOmZOhZb6JD5GXZb9ztv fVUsY4gVH3LMjmaZGHPrcZOyXkDHo0EdTlOcOj75xtTp5OtsMlQe++09FpatnUwh pfqx3O0nR2n/FayVFrhIZY0= Received: (qmail 47214 invoked by alias); 1 Oct 2015 18:54:59 -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 47192 invoked by uid 89); 1 Oct 2015 18:54:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL, BAYES_20, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 01 Oct 2015 18:54: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 t91IstPI007758 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 1 Oct 2015 11:54:55 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id t91Ist0k007757; Thu, 1 Oct 2015 11:54:55 -0700 (PDT) (envelope-from sgk) Date: Thu, 1 Oct 2015 11:54:54 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] fortran/67802 -- Numeric constant character length must ... Message-ID: <20151001185454.GA7728@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) be an integer expression. The attached patch checks that a numerical constant in a CHARACTER(LEN=x) declaration is an integer. Regression tested on x86_64-*-freebsd*. OK to commit? 2015-10-01 Steven G. Kargl PR fortran/67802 * decl.c (add_init_expr_to_sym): Numeric constant for character length must be an INTEGER. 2015-10-01 Steven G. Kargl PR fortran/67802 * gfortran.dg/pr67802.f90: New test. Index: fortran/decl.c =================================================================== --- fortran/decl.c (revision 228306) +++ fortran/decl.c (working copy) @@ -1439,7 +1439,16 @@ add_init_expr_to_sym (const char *name, /* Update initializer character length according symbol. */ else if (sym->ts.u.cl->length->expr_type == EXPR_CONSTANT) { - int len = mpz_get_si (sym->ts.u.cl->length->value.integer); + int len; + + if (sym->ts.u.cl->length->ts.type != BT_INTEGER) + { + gfc_error ("Expecting an scalar-int-expr at %L", + &sym->ts.u.cl->length->where); + return false; + } + + len = mpz_get_si (sym->ts.u.cl->length->value.integer); if (init->expr_type == EXPR_CONSTANT) gfc_set_constant_character_len (len, init, -1); Index: testsuite/gfortran.dg/pr67802.f90 =================================================================== --- testsuite/gfortran.dg/pr67802.f90 (revision 0) +++ testsuite/gfortran.dg/pr67802.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/67802 +! Original code contribute by gerhard.steinmetz.fortran at t-online.de +program p + character(1.) :: c1 = ' ' ! { dg-error "Expecting an scalar-int-expr" } + character(1d1) :: c2 = ' ' ! { dg-error "Expecting an scalar-int-expr" } + character((0.,1.)) :: c3 = ' ' ! { dg-error "Expecting an scalar-int-expr" } + character(.true.) :: c4 = ' ' ! { dg-error "Expecting an scalar-int-expr" } +end program p