From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7E8893856DC8; Tue, 15 Aug 2023 15:15:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E8893856DC8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692112510; bh=dDrKoGDZvF2uFDZrP+tKdEgHSwtkRj+R8QZjsrC5Jyc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=v3uUvvgayN1e428yUkqs2/Y9RMGlF1mrhVmSLNyb0HT+I9Rdcqt6vQjLGNahAJzKv ayNfcsVjr4QzceqzJuktSqH3MC1bSiKadsPdcLK944nXw+15WqCvM11ZZaMcDgSCk9 4i5hJGzOvg1N84QIJj49NmnPZipfSe4lDqkAl26k= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/110677] UBSAN error: load of value 1818451807, which is not a valid value for type 'expr_t' when compiling pr49213.f90 Date: Tue, 15 Aug 2023 15:15:09 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110677 --- Comment #3 from CVS Commits --- The master branch has been updated by Martin Jambor : https://gcc.gnu.org/g:84e122c34834d9dea189c10fe0bf60c4d1a99fae commit r14-3224-g84e122c34834d9dea189c10fe0bf60c4d1a99fae Author: Martin Jambor Date: Tue Aug 15 17:13:44 2023 +0200 Fortran: Avoid accessing gfc_charlen when not looking at BT_CHARACTER (= PR 110677) This patch addresses an issue uncovered by the undefined behavior sanitizer. In function resolve_structure_cons in resolve.cc there is a test starting with: if (cons->expr->ts.type =3D=3D BT_CHARACTER && comp->ts.u.cl && comp->ts.u.cl->length && comp->ts.u.cl->length->expr_type =3D=3D EXPR_CONSTANT and UBSAN complained of loads from comp->ts.u.cl->length->expr_type of integer value 1818451807 which is outside of the value range expr_t enum. If I understand the code correctly it the entire load was unwanted because comp->ts.type in those cases is BT_CLASS and not BT_CHARACTER. This patch simply adds a check to make sure it is only accessed in those cases. During review, Harald Anlauf noticed that length types also need to be checked and so I added also checks that he suggested to the condition. Co-authored-by: Harald Anlauf gcc/fortran/ChangeLog: 2023-08-14 Martin Jambor PR fortran/110677 * resolve.cc (resolve_structure_cons): Check comp->ts is charac= ter type before accessing stuff through comp->ts.u.cl.=