From patchwork Sat Jan 5 13:28:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janus Weil X-Patchwork-Id: 1020966 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-493439-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SA3SD1lU"; 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 43X2Yd2mdYz9s3l for ; Sun, 6 Jan 2019 00:29:07 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=cq/fskq8hK3L8f6sWHmGypy4iS7kUr+Q1RV3xcSNS92F/O JgY9otYYEW9koDpRow+vaJjgjgzdyul3fgUgXHLxg6TvTPSDttklusu1Z9prqqas FiJ+fXprJHkSBs3eTP41vh5Zkh7BWbnXV0xlLt7v9e7OPdmhRRRJtx5F1I+8Q= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=9BQy5+WZdCckiXnvLfF9Z7qnRBY=; b=SA3SD1lU0BlymIdHa3In QXJF4GZ15Yk/7Sg1bChACTrH+lrSPZJ4KsAeADwNom8K8DIJw92Wd0xkt2d0au6Z 4tawSte7kzSWr1MVSVF3bcH3e9NJh7UrCc/Jka0Wt/f24xzFAFz3iCesyMkOo18b bdyU1a6n4JgfNE3SJxitHqo= Received: (qmail 75279 invoked by alias); 5 Jan 2019 13:29:00 -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 75259 invoked by uid 89); 5 Jan 2019 13:28:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Automatic, formal, UD:cl, weil X-HELO: mail-oi1-f181.google.com Received: from mail-oi1-f181.google.com (HELO mail-oi1-f181.google.com) (209.85.167.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 05 Jan 2019 13:28:56 +0000 Received: by mail-oi1-f181.google.com with SMTP id x23so32544858oix.3; Sat, 05 Jan 2019 05:28:56 -0800 (PST) MIME-Version: 1.0 From: Janus Weil Date: Sat, 5 Jan 2019 14:28:42 +0100 Message-ID: Subject: [Patch, Fortran] PR 88009: [9 Regression] ICE in find_intrinsic_vtab, at fortran/class.c:2761 To: gfortran , gcc-patches Hi all, the attached patch fixes PR 88009, an ICE-on-invalid regression caused by one of my earlier commits. Apart from adding some extra checks to avoid ICEs, it also uses the 'artificial' attribute to suppress bogus errors (see comment #3) and does some minor cleanup in resolve_fl_variable. Regtests cleanly on x86_64-linux-gnu. Ok for trunk? Cheers, Janus 2019-01-05 Janus Weil PR fortran/88009 * class.c (gfc_find_derived_vtab): Mark the _final component as artificial. (find_intrinsic_vtab): Ditto. Also add an extra check to avoid dereferencing a null pointer and adjust indentation. * resolve.c (resolve_fl_variable): Add extra check to avoid dereferencing a null pointer. Move variable declarations to local scope. (resolve_fl_procedure): Add extra check to avoid dereferencing a null pointer. * symbol.c (check_conflict): Suppress errors for artificial symbols. 2019-01-05 Janus Weil PR fortran/88009 * gfortran.dg/blockdata_10.f90: New test case. diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c index e55ab25882f..77f0fca9385 100644 --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -2466,6 +2466,7 @@ gfc_find_derived_vtab (gfc_symbol *derived) goto cleanup; c->attr.proc_pointer = 1; c->attr.access = ACCESS_PRIVATE; + c->attr.artificial = 1; c->tb = XCNEW (gfc_typebound_proc); c->tb->ppc = 1; generate_finalization_wrapper (derived, ns, tname, c); @@ -2762,9 +2763,9 @@ find_intrinsic_vtab (gfc_typespec *ts) /* This is elemental so that arrays are automatically treated correctly by the scalarizer. */ copy->attr.elemental = 1; - if (ns->proc_name->attr.flavor == FL_MODULE) + if (ns->proc_name && ns->proc_name->attr.flavor == FL_MODULE) copy->module = ns->proc_name->name; - gfc_set_sym_referenced (copy); + gfc_set_sym_referenced (copy); /* Set up formal arguments. */ gfc_get_symbol ("src", sub_ns, &src); src->ts.type = ts->type; @@ -2798,6 +2799,7 @@ find_intrinsic_vtab (gfc_typespec *ts) goto cleanup; c->attr.proc_pointer = 1; c->attr.access = ACCESS_PRIVATE; + c->attr.artificial = 1; c->tb = XCNEW (gfc_typebound_proc); c->tb->ppc = 1; c->initializer = gfc_get_null_expr (NULL); diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index a498d19e411..beafe8da8bc 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -12274,13 +12274,8 @@ deferred_requirements (gfc_symbol *sym) static bool resolve_fl_variable (gfc_symbol *sym, int mp_flag) { - int no_init_flag, automatic_flag; - gfc_expr *e; - const char *auto_save_msg; - bool saved_specification_expr; - - auto_save_msg = "Automatic object %qs at %L cannot have the " - "SAVE attribute"; + const char *auto_save_msg = "Automatic object %qs at %L cannot have the " + "SAVE attribute"; if (!resolve_fl_var_and_proc (sym, mp_flag)) return false; @@ -12288,7 +12283,7 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) /* Set this flag to check that variables are parameters of all entries. This check is effected by the call to gfc_resolve_expr through is_non_constant_shape_array. */ - saved_specification_expr = specification_expr; + bool saved_specification_expr = specification_expr; specification_expr = true; if (sym->ns->proc_name @@ -12315,6 +12310,8 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) { /* Make sure that character string variables with assumed length are dummy arguments. */ + gfc_expr *e = NULL; + if (sym->ts.u.cl) e = sym->ts.u.cl->length; else @@ -12364,7 +12361,7 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) apply_default_init_local (sym); /* Try to apply a default initialization. */ /* Determine if the symbol may not have an initializer. */ - no_init_flag = automatic_flag = 0; + int no_init_flag = 0, automatic_flag = 0; if (sym->attr.allocatable || sym->attr.external || sym->attr.dummy || sym->attr.intrinsic || sym->attr.result) no_init_flag = 1; @@ -12494,7 +12491,7 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag) module procedures are excluded by 2.2.3.3 - i.e., they are not externally accessible and can access all the objects accessible in the host. */ - if (!(sym->ns->parent + if (!(sym->ns->parent && sym->ns->parent->proc_name && sym->ns->parent->proc_name->attr.flavor == FL_MODULE) && gfc_check_symbol_access (sym)) { diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index a88e7c01df7..cd52c73031b 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -440,6 +440,9 @@ check_conflict (symbol_attribute *attr, const char *name, locus *where) const char *a1, *a2; int standard; + if (attr->artificial) + return true; + if (where == NULL) where = &gfc_current_locus; diff --git a/gcc/testsuite/gfortran.dg/blockdata_10.f90 b/gcc/testsuite/gfortran.dg/blockdata_10.f90 new file mode 100644 index 00000000000..ce7ba25c269 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/blockdata_10.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! +! PR 88009: [9 Regression] ICE in find_intrinsic_vtab, at fortran/class.c:2761 +! +! Contributed by G. Steinmetz + +module m + class(*), allocatable :: z +end +block data + use m + z = 'z' ! { dg-error "assignment statement is not allowed|Unexpected assignment statement" } +end