From patchwork Fri Sep 25 19:18:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 522961 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 6D17E140772 for ; Sat, 26 Sep 2015 05:18:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=X+iuPDR4; 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=aSXPYrZxl0QR1+va5xN7Vamx60U2z0kML1meOYROgQgVUdG3MseDr El+gKYnn+cdS5Yjy/zFpEc37b4+l4SQEm8uknxQDJiDS/zx8Qo5SAg8+cLHLJl1x vRFCAMGLe5PuR1dJwjBXQPXGS6reV7b9/Yy0Qed4ti44o9QrlFRDEw= 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=1l3HLrDudRQRfdjpl9XjL2/uV38=; b=X+iuPDR4ScWaW4eDqXFQ jRHUD6ZTOeDVrPQ6/IlxZff5fCdXd//v4C2btmEjdgtetW6WzwLiQ4BCbBQfpvMk Tdj1UHbBjSl4rRpNHqs0f1YZUZrrbrD1I5YnHC8WUJcURuNIQcT4iekF98o1y2Ti GN3TtDx061nk0ZaZpZRY6ws= Received: (qmail 82814 invoked by alias); 25 Sep 2015 19:18:28 -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 81255 invoked by uid 89); 25 Sep 2015 19:18:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, 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; Fri, 25 Sep 2015 19:18:25 +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 t8PJINXS094072 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 25 Sep 2015 12:18:23 -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 t8PJINYv094071; Fri, 25 Sep 2015 12:18:23 -0700 (PDT) (envelope-from sgk) Date: Fri, 25 Sep 2015 12:18:23 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] fortran/67614 -- Detect an invalid NULL in an arithmetic if Message-ID: <20150925191823.GB94019@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) The attached patch has been built and regression tested on x86_64-*-freebsd. There were no regression. If the scalar-numeric-expr in an arithmetic-if is ar reference to NULL(), this is an invalid expression. By resolving the expression, then entity is correctly identified by EXPR_NULL. Thus, the patch prevents an ICE when a messed up non-scalar-numeric-expr is later translated in SSA form. 2015-09-25 Steven G. Kargl PR fortran/67614 * resolve.c (gfc_resolve_code): Prevent ICE for invalid EXPR_NULL. 2015-09-25 Steven G. Kargl PR fortran/67614 * gfortran.dg/pr67614.f90: New test. Index: fortran/resolve.c =================================================================== --- fortran/resolve.c (revision 228061) +++ fortran/resolve.c (working copy) @@ -10380,10 +10380,14 @@ gfc_resolve_code (gfc_code *code, gfc_na { gfc_expr *e = code->expr1; + gfc_resolve_expr (e); + if (e->expr_type == EXPR_NULL) + gfc_error ("Invalid NULL at %L", &e->where); + if (t && (e->rank > 0 || !(e->ts.type == BT_REAL || e->ts.type == BT_INTEGER))) gfc_error ("Arithmetic IF statement at %L requires a scalar " - "REAL or INTEGER expression", &code->expr1->where); + "REAL or INTEGER expression", &e->where); resolve_branch (code->label1, code); resolve_branch (code->label2, code); Index: testsuite/gfortran.dg/pr67614.f90 =================================================================== --- testsuite/gfortran.dg/pr67614.f90 (revision 0) +++ testsuite/gfortran.dg/pr67614.f90 (working copy) @@ -0,0 +1,12 @@ +! { dg-do compile } +! { dg-options "-std=legacy" } +! PR fortran/67614 +! +program foo + implicit none + integer, pointer :: z + if (null(z)) 10, 20, 30 ! { dg-error "Invalid NULL" } +10 continue +20 continue +30 continue +end program foo