From patchwork Wed Jan 10 23:28:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 858633 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-470761-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TX7bpt3s"; 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 3zH4vm22dbz9s7c for ; Thu, 11 Jan 2018 10:28:52 +1100 (AEDT) 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=gI8R7Dx4Ba+ZBfnpu6HFDdWAQYU5kdH6BXSTR5di+RX uLAY8QLuRH6NOJYQLY0QeN4vjRxV/N0Gv9t34ACS+AYBdj2k3S/QR87x67bA5RzQ 0XJOnW16xrIJSCWUKdfoNzZ9L5oHS89fOVXWqWSxM6WyX1YrTlZI7HuQPmwbgfRE = 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=LfTgHYYN0MT8nLVXfUzxod4DLNg=; b=TX7bpt3sYeoivrIeW pmukMJoq+L7Xl6+SkFehTMBcxpFOyy8MSRS3tD1kIXVPBWe/2OV8SEYtAOov/9M8 GLggUFuarl2rzdS3W8QfMLqd6pjWO6SzQeT74oLGDcccjljE1WKTWeVmxhOhjbeI kRiRh6/5IwF4xYisKIMGlKnWKc= Received: (qmail 8121 invoked by alias); 10 Jan 2018 23:28:45 -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 8102 invoked by uid 89); 10 Jan 2018 23:28:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Star 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; Wed, 10 Jan 2018 23:28:43 +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 w0ANSfUZ075448 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 10 Jan 2018 15:28:41 -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 w0ANSftP075447; Wed, 10 Jan 2018 15:28:41 -0800 (PST) (envelope-from sgk) Date: Wed, 10 Jan 2018 15:28:41 -0800 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [Committed] PR Fortran/82367 -- Check for NULL pointer. Message-ID: <20180110232841.GA75414@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) Thomas Koenig approved the patch in the PR. Regression tested on x86_64-*-freebsd 2018-01-10 Steven G. Kargl PR fortran/82367 * resolve.c (resolve_allocate_expr): Check for NULL pointer. 2018-01-10 Steven G. Kargl PR fortran/82367 * gfortran.dg/deferred_character_18.f90: New test. Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 256455) +++ gcc/fortran/resolve.c (working copy) @@ -7484,8 +7484,13 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bo if (code->ext.alloc.ts.type == BT_CHARACTER && !e->ts.deferred && !UNLIMITED_POLY (e)) { - int cmp = gfc_dep_compare_expr (e->ts.u.cl->length, - code->ext.alloc.ts.u.cl->length); + int cmp; + + if (!e->ts.u.cl->length) + goto failure; + + cmp = gfc_dep_compare_expr (e->ts.u.cl->length, + code->ext.alloc.ts.u.cl->length); if (cmp == 1 || cmp == -1 || cmp == -3) { gfc_error ("Allocating %s at %L with type-spec requires the same " Index: gcc/testsuite/gfortran.dg/deferred_character_18.f90 =================================================================== --- gcc/testsuite/gfortran.dg/deferred_character_18.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/deferred_character_18.f90 (working copy) @@ -0,0 +1,29 @@ +! { dg-do compile } +! PR Fortran/82367 +! Contributed by Walter Spector +module cls_allocmod + implicit none + +contains + + subroutine cls_alloc (n, str) + integer, intent(in) :: n + character(*), allocatable, intent(out) :: str +! Note: Star ^ should have been a colon (:) + + allocate (character(n)::str) + + end subroutine + +end module + +program cls + use cls_allocmod + implicit none + + character(:), allocatable :: s + + call cls_alloc(42, s) ! { dg-error "allocatable or pointer dummy argument" } + print *, 'string len =', len(s) + +end program