From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 24F7D3851C08; Sat, 6 Jun 2020 19:59:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24F7D3851C08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591473548; bh=/vm0HjsYnPZebrnDlps1BVR8UM3AfIm3Krxkabmxy/w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bI8x1AcakttpO73Y6Og9W7yG25C2cSfeoq5S8hy4zZMHOF8fyGaCAfiXITXLueq6D WRwhjiyYkJdfRkuzgvQcHL2vjULSvDxhmh+h364S3BVi+3jCNfRszOA5S94Du3+kmo I5LQIlhB7u+S5DCv4VQAr2wAoWrGLjszov6mce0Q= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/95512] gcc/fortran/trans-decl.c:1066: array sanity check after use Date: Sat, 06 Jun 2020 19:59:08 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: WAITING 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: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jun 2020 19:59:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95512 --- Comment #3 from anlauf at gcc dot gnu.org --- I didn't write the code, but for more context: trans.h has: #define GFC_TYPE_ARRAY_LBOUND(node, dim) \ (TYPE_LANG_SPECIFIC(node)->lbound[dim]) #define GFC_TYPE_ARRAY_UBOUND(node, dim) \ (TYPE_LANG_SPECIFIC(node)->ubound[dim]) The loop in trans-decl.c: for (dim =3D GFC_TYPE_ARRAY_RANK (type); dim < GFC_TYPE_ARRAY_RANK (type) + GFC_TYPE_ARRAY_CORANK (type); dim= ++) { if (GFC_TYPE_ARRAY_LBOUND (type, dim) =3D=3D NULL_TREE) { GFC_TYPE_ARRAY_LBOUND (type, dim) =3D create_index_var ("lbound", nest); TREE_NO_WARNING (GFC_TYPE_ARRAY_LBOUND (type, dim)) =3D 1; } /* Don't try to use the unknown ubound for the last coarray dimension= .=20 */ if (GFC_TYPE_ARRAY_UBOUND (type, dim) =3D=3D NULL_TREE && dim < GFC_TYPE_ARRAY_RANK (type) + GFC_TYPE_ARRAY_CORANK (type= ) - 1) { GFC_TYPE_ARRAY_UBOUND (type, dim) =3D create_index_var ("ubound", nest); TREE_NO_WARNING (GFC_TYPE_ARRAY_UBOUND (type, dim)) =3D 1; } } So the relevant check is in the loop header, and the current check is there for the last index. Maybe it is bad style, but I still consider it a false positive. cppcheck's view is probably too narrow to understand the range of dim.=