From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 72E343858C35; Wed, 8 May 2024 19:26:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72E343858C35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715196364; bh=3ec1rygUA8YXYOQuO6SqdNeZ01xNi3/oGIZcospiEKE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=F+raazNhODjJRe5KgiA9it6UlRT86UME0RuiHyzScfFc4b4KZJaXtEPAwdaZCeS3E AF+NZOY21RRG/4mICuTHFF02ICQS8G4+tLzbMqv8fU2bbLzPrKYerGN5tfMt6+j//8 qANbKdp+iNM2yJRC+xSbWiKMLnafVhvXRxgoBVMo= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/86100] Spurious error with -fcheck=bounds and allocatable class(*) array components Date: Wed, 08 May 2024 19:26:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 8.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D86100 anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |anlauf at gcc dot gnu.org --- Comment #2 from anlauf at gcc dot gnu.org --- The problem seems to generally occur for class components of derived types. program p implicit none type t integer :: i =3D 0 end type t type any_matrix class(t), allocatable :: m(:,:) end type any_matrix type(any_matrix) :: a, b allocate(a%m(3,4)) call foo () contains subroutine foo () b =3D a ! Array bound mismatch for dimension 1 of array '<>' (12/3) !b%m =3D a%m ! no runtime error with -fcheck=3Dbounds end subroutine foo end This fails as indicated. Note that 12=3D3*4 is the total size of the array, and 3 is the size of the first dimension, which - along with the '<>' - points to gfc_copy_class_to_class: from_len =3D gfc_conv_descriptor_size (from_data, 1); from_len =3D fold_convert (TREE_TYPE (orig_nelems), from_len); tmp =3D fold_build2_loc (input_location, NE_EXPR, logical_type_node, from_len, orig_nelems); msg =3D xasprintf ("Array bound mismatch for dimension %d " "of array '%s' (%%ld/%%ld)", 1, name); gfc_trans_runtime_check (true, false, tmp, &body, &gfc_current_locus, msg, fold_convert (long_integer_type_node, orig_nelems), fold_convert (long_integer_type_node, from_len)); So we compare dimension 1 and the full size of the rhs? Shouldn't we compare lhs and rhs shapes?=