From patchwork Fri Oct 4 18:18:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1171989 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-510296-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZzdEBiFW"; dkim-atps=neutral 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 46lJ6b6bxxz9sPl for ; Sat, 5 Oct 2019 04:19:02 +1000 (AEST) 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=RvAtWKCktvOeWgBXB/t3Xkjnhr6Ti54oQunmug+odrC HxwFGWehLidQ4bi0/83U9BBcewqYnDY1pOfL+N8NduGEGa5yY2b3zhtxHO99f7M9 lxclLLmsCKVtGKYSBXzemztAjWu/JUOiJJqR5r0ADTy0qIrRyzC4HVaffSXf6k7E = 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=XdgRevoSJIn1PDvf8TZyv4oTN6o=; b=ZzdEBiFWgc/avcg5v Byi+mDiESYbpJQ3fp6U1hLf5HiIY/w1pWBhtw0YJ2PDIDKKWvmEHw0ahD52mBbC3 GE2lpsoWa2B2ufP12mss41CeWopgqtBdgDcCN5o0/hxiDx1xaohpnsOOEh1xXUfW gytS7O7cNeYZqTHmulqgIgWuFI= Received: (qmail 64119 invoked by alias); 4 Oct 2019 18:18:55 -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 64098 invoked by uid 89); 4 Oct 2019 18:18:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=burn, Burn, Steinmetz, x86_64-*-freebsd 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, 04 Oct 2019 18:18:53 +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 x94IIpFO053741 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 4 Oct 2019 11:18:51 -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 x94IIpbs053647; Fri, 4 Oct 2019 11:18:51 -0700 (PDT) (envelope-from sgk) Date: Fri, 4 Oct 2019 11:18:51 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/91959 -- Re-arrange matching of %FILL Message-ID: <20191004181851.GA27050@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) The attached patch has been tested on x86_64-*-freebsd. OK to commit. Apparently, DEC Fortran allows one to use %FILL as a variable name. When the -fdec code was added to gfortran, variable_decl was updated to match %FILL. This was done by first ilooking for the % character, and if found, it is burned and FILL is then match. Unfortunately, as the new testcase shows this allowed any variable starting with % to match. The patch re-arranges the code so that an error is issues for variables starting with %, which are not %FILL. 2019-10-04 Steven G. Kargl PR fortran.91959 * fortran/decl.c (variable_decl): Re-arrange code for matching %FILL. 2019-10-04 Steven G. Kargl PR fortran.91959 * gfortran.dg/pr91959.f90: New test. Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 276593) +++ gcc/fortran/decl.c (working copy) @@ -2441,6 +2441,7 @@ variable_decl (int elem) match m; bool t; gfc_symbol *sym; + char c; initializer = NULL; as = NULL; @@ -2454,40 +2455,45 @@ variable_decl (int elem) name to be '%FILL' which gives it an anonymous (inaccessible) name. */ m = MATCH_NO; gfc_gobble_whitespace (); - if (gfc_peek_ascii_char () == '%') + c = gfc_peek_ascii_char (); + if (c == '%') { - gfc_next_ascii_char (); + gfc_next_ascii_char (); /* Burn % character. */ m = gfc_match ("fill"); - } - - if (m != MATCH_YES) - { - m = gfc_match_name (name); - if (m != MATCH_YES) - goto cleanup; - } - - else - { - m = MATCH_ERROR; - if (gfc_current_state () != COMP_STRUCTURE) + if (m == MATCH_YES) { - if (flag_dec_structure) - gfc_error ("%qs not allowed outside STRUCTURE at %C", "%FILL"); - else - gfc_error ("%qs at %C is a DEC extension, enable with " + if (gfc_current_state () != COMP_STRUCTURE) + { + if (flag_dec_structure) + gfc_error ("%qs not allowed outside STRUCTURE at %C", "%FILL"); + else + gfc_error ("%qs at %C is a DEC extension, enable with " "%<-fdec-structure%>", "%FILL"); - goto cleanup; - } + m = MATCH_ERROR; + goto cleanup; + } - if (attr_seen) + if (attr_seen) + { + gfc_error ("%qs entity cannot have attributes at %C", "%FILL"); + m = MATCH_ERROR; + goto cleanup; + } + + /* %FILL components are given invalid fortran names. */ + snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "%%FILL%u", fill_id++); + } + else { - gfc_error ("%qs entity cannot have attributes at %C", "%FILL"); - goto cleanup; + gfc_error ("Invalid character %qc in variable name at %C", c); + return MATCH_ERROR; } - - /* %FILL components are given invalid fortran names. */ - snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "%%FILL%u", fill_id++); + } + else + { + m = gfc_match_name (name); + if (m != MATCH_YES) + goto cleanup; } var_locus = gfc_current_locus; Index: gcc/testsuite/gfortran.dg/pr91959.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr91959.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr91959.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/91959 +! Code contributed by Gerhard Steinmetz +program p + implicit none + integer :: %a ! { dg-error "Invalid character" } + a = 1 ! { dg-error "has no IMPLICIT type" } + print *, a +end