From patchwork Wed Jul 26 19:10:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 126533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp607958vqo; Wed, 26 Jul 2023 12:11:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlHYQv0Qd937ra37GBLLHy88NUBK+Bc4cml9HUqHXoGm7/FER5UZINlm3kdv/79IdW8WpklF X-Received: by 2002:a19:675d:0:b0:4fe:e6f:bb10 with SMTP id e29-20020a19675d000000b004fe0e6fbb10mr35228lfj.44.1690398673857; Wed, 26 Jul 2023 12:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690398673; cv=none; d=google.com; s=arc-20160816; b=qhhNIZbuGrMUcOjqpDwF0RBcWbuybo98MVzKxLmtdwC97ZiX+oG3Tylwfafb4BkVvF sdnGi8kjLWo97mdxBZJoyTfGfrbVuEyMtMfY8UgASb2RV9JfcIRgTniZ1lzX9c2dUoLt 57YxluU1M2jOEryrNL4sFB3UpAztpLdd0kyzx+5PNYMxkcGsW5TpcAXyjTs5PleLIl+4 NOiY159N8UDf+Z1bhp6KrR/gMElqCyaNTx2XK+tOEVOI9daaTtDFDkHYBsiuwCQVl3B7 EEGRJ4/UJeziH3c212r90EJmsrcgEayWthTw+/hyFfKmx9bCAl4BcuOXcxlC60rl/ffj ZPCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=CZWwH3MvX4kPqVHT4S4j3t7ey/SPU2mu6z34HwergsE=; fh=QK0YdXSiSCa48e9o4Ff7k6xpBN/ax2bSUZqWzYlsl7Q=; b=GDGjXqR8WCYrLF+iq5GLPIOp6cg9BxY2sD3vb0Bq0TR9lmt4FdZHujFIoF1CAkOMP5 fOh8z0zv9mkk+vGvUuuNu9g4CHkOSwAKl9Qzoxok+YDTMwJioK3OvwFQ8vHw/zXH/xBn jKV886jzHzaEMnXpU2kE4dKmrGpa45h6miVujtywjuOCzPqyU7L0CoseARsUpyORN+qB nYWaRY0vnCo872JINFCuSewJQZvMabTACVxB5+aP5/CvOro2C4PjOhBHfU/8LzVMrCeK y4VpsyejQpWqZdzftnFtJTD/gScQlsK24ofHykbFbg1srz36m4vgXXLP6pN6gXZ6cOVe cypw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l3V5EAUi; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t13-20020aa7d70d000000b00522205a4d35si5985054edq.103.2023.07.26.12.11.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 12:11:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l3V5EAUi; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C2D83858039 for ; Wed, 26 Jul 2023 19:11:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C2D83858039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690398667; bh=CZWwH3MvX4kPqVHT4S4j3t7ey/SPU2mu6z34HwergsE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=l3V5EAUioMnRSSXmLaeDXW/QbOL21mbjEOwoqv9+MPH5H0HKjEcJsZzQL3J7Uh0RC LpEIb+Hz8h3lhII2uyEoI6etbhgIGDIXSKhdLaJ2QIQ+JxJoD87KvSdWMYqQI5YF9q MTOSYYbcZvlTPPjTp0gNk/6y/sOYwHs+fGLf5xt4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by sourceware.org (Postfix) with ESMTPS id ACD3A3858D35; Wed, 26 Jul 2023 19:10:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACD3A3858D35 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.5.69] ([79.251.5.69]) by web-mail.gmx.net (3c-app-gmx-bap18.server.lan [172.19.172.88]) (via HTTP); Wed, 26 Jul 2023 21:10:20 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: diagnose strings of non-constant length in DATA statements [PR68569] Date: Wed, 26 Jul 2023 21:10:20 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:TD6qV6GMh4h1auBNVMyYMfFI8dChaMHUBZl5b76HqBtHh70JDdA95lszHyzRKZY3OZ5hm YHdctQfkr5j/vs41VqNc7yAuUcEQc+V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fp uYE/KxcQkd5uIxv7GlNYcnwg== X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772511479392167940 X-GMAIL-MSGID: 1772511479392167940 Dear all, the attached patch fixes an ICE-on-invalid after use of strings of non-constant length in DATA statements. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From b5b13db48c169ef18a8b75739bd4f22f9fd5654e Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 26 Jul 2023 20:46:50 +0200 Subject: [PATCH] Fortran: diagnose strings of non-constant length in DATA statements [PR68569] gcc/fortran/ChangeLog: PR fortran/68569 * resolve.cc (check_data_variable): Do not accept strings with deferred length or non-constant length in a DATA statement. Reject also substrings of string variables of non-constant length. gcc/testsuite/ChangeLog: PR fortran/68569 * gfortran.dg/data_char_6.f90: New test. --- gcc/fortran/resolve.cc | 22 ++++++++++++++++++- gcc/testsuite/gfortran.dg/data_char_6.f90 | 26 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/data_char_6.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index f7cfdfc133f..3cd470ddcca 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -16771,7 +16771,6 @@ check_data_variable (gfc_data_variable *var, locus *where) return false; ar = NULL; - mpz_init_set_si (offset, 0); e = var->expr; if (e->expr_type == EXPR_FUNCTION && e->value.function.isym @@ -16838,8 +16837,24 @@ check_data_variable (gfc_data_variable *var, locus *where) "attribute", ref->u.c.component->name, &e->where); return false; } + + /* Reject substrings of strings of non-constant length. */ + if (ref->type == REF_SUBSTRING + && ref->u.ss.length + && ref->u.ss.length->length + && !gfc_is_constant_expr (ref->u.ss.length->length)) + goto bad_charlen; } + /* Reject strings with deferred length or non-constant length. */ + if (e->ts.type == BT_CHARACTER + && (e->ts.deferred + || (e->ts.u.cl->length + && !gfc_is_constant_expr (e->ts.u.cl->length)))) + goto bad_charlen; + + mpz_init_set_si (offset, 0); + if (e->rank == 0 || has_pointer) { mpz_init_set_ui (size, 1); @@ -16967,6 +16982,11 @@ check_data_variable (gfc_data_variable *var, locus *where) mpz_clear (offset); return t; + +bad_charlen: + gfc_error ("Non-constant character length at %L in DATA statement", + &e->where); + return false; } diff --git a/gcc/testsuite/gfortran.dg/data_char_6.f90 b/gcc/testsuite/gfortran.dg/data_char_6.f90 new file mode 100644 index 00000000000..4e32c647d4d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/data_char_6.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! PR fortran/68569 - ICE with automatic character object and DATA +! Contributed by G. Steinmetz + +subroutine s1 (n) + implicit none + integer, intent(in) :: n + character(n) :: x + data x /'a'/ ! { dg-error "Non-constant character length" } +end + +subroutine s2 (n) + implicit none + integer, intent(in) :: n + character(n) :: x + data x(1:1) /'a'/ ! { dg-error "Non-constant character length" } +end + +subroutine s3 () + implicit none + type t + character(:) :: c ! { dg-error "must be a POINTER or ALLOCATABLE" } + end type t + type(t) :: tp + data tp%c /'a'/ ! { dg-error "Non-constant character length" } +end -- 2.35.3