From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4044 invoked by alias); 27 Nov 2013 15:55:01 -0000 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 Received: (qmail 3682 invoked by uid 48); 27 Nov 2013 15:54:57 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/57904] [4.9 Regression] Bogus(?) "invokes undefined behavior" warning with Fortran's finalization wrapper (gfortran.dg/class_48.f90) Date: Wed, 27 Nov 2013 15:55:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.9.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-11/txt/msg02812.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57904 --- Comment #5 from Jakub Jelinek --- We have: : ubound.0_3 = 0; size.1_4 = ubound.0_3 + 1; size.1_5 = MAX_EXPR ; _6 = size.1_5 * 4; _7 = (character(kind=4)) _6; _8 = MAX_EXPR <_7, 1>; sizes_9 = __builtin_malloc (_8); size.3_10 = MAX_EXPR ; _11 = size.3_10 * 4; _12 = (character(kind=4)) _11; _13 = MAX_EXPR <_12, 1>; strides_14 = __builtin_malloc (_13); MEM[(integer(kind=4)[0:D.1906] *)sizes_9][0] = 1; if (ubound.0_3 > 0) goto ; else goto ; : idx_50 = 1; : # idx_15 = PHI <1(3), idx_25(5)> _16 = idx_15 + -1; _17 = array_1(D)->dim[_16].stride; MEM[(integer(kind=4)[0:D.1900] *)strides_14][_16] = _17; _18 = MEM[(integer(kind=4)[0:D.1906] *)sizes_9][_16]; _19 = array_1(D)->dim[_16].ubound; _20 = array_1(D)->dim[_16].lbound; _21 = _19 - _20; _22 = _21 + 1; _23 = MAX_EXPR <_22, 0>; _24 = _18 * _23; MEM[(integer(kind=4)[0:D.1906] *)sizes_9][idx_15] = _24; idx_25 = idx_15 + 1; if (ubound.0_3 == idx_15) goto ; else goto ; : goto ; and the warning is on the header(4) latch(5) loop. The warning is correct, the loop would execute 0xffffffff times and _16 = idx_15 + -1 would invoke undefined behavior on the last iteration, but still the warning is undesirable because it is on a dead loop. Only during IPA optimizations the original _15 = array_14(D)->dtype; ubound.0_16 = _15 & 7; was optimized into: _2 = 344; ubound.0_3 = _2 & 7; and only copyprop2 pass optimizes that into: ubound.0_3 = 0; but nothing yet propagated it into the condition and folded the condition, cunrolli runs simply too early. I guess scheduling there a forwprop pass in between copyprop2 and cunrolli would fix this, but don't know how expensive it is. Or we could avoid emitting the warning right away, but add there __builtin_warning or similar into the loop, and only warn later on after some cleanup passes that can actually figure out what code is dead.