From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11914 invoked by alias); 12 Jun 2012 08:09:11 -0000 Received: (qmail 11894 invoked by uid 22791); 12 Jun 2012 08:09:08 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Jun 2012 08:08:55 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/53642] New: Front-end optimization: Wrong string length for deferred-length strings Date: Tue, 12 Jun 2012 08:09:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-06/txt/msg00658.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53642 Bug #: 53642 Summary: Front-end optimization: Wrong string length for deferred-length strings Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: burnus@gcc.gnu.org CC: damian@rouson.net, tkoenig@gcc.gnu.org As reported by Damian Rouson at http://gcc.gnu.org/ml/fortran/2012-06/msg00069.html Without optimization, the following program prints - and should print: 3 3 However, with -ffrontend-optimize the result is, wrongly, 3 4 Damian: Use -fno-frontend-optimize as work-around. character(len=4) :: string="123 " character(:), allocatable :: trimmed trimmed = trim(string) print *,len_trim(string),len(trimmed) end >>From the original dump: (a) Without FE optimization _gfortran_string_trim (&len.1, (void * *) &pstr.0, 4, &string); D.1864 = len.1; if (trimmed != 0B) goto L.1; trimmed = (character(kind=1)[1:.trimmed] *) __builtin_malloc ((sizetype) len.1); ... .trimmed = len.1; (b) With FE optimization if (trimmed != 0B) goto L.1; trimmed = (character(kind=1)[1:.trimmed] *) __builtin_malloc (4); ... .trimmed = 4;