From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28507 invoked by alias); 30 Mar 2007 11:01:16 -0000 Received: (qmail 28407 invoked by uid 48); 30 Mar 2007 11:01:02 -0000 Date: Fri, 30 Mar 2007 11:01:00 -0000 Subject: [Bug fortran/31399] New: Wrong code for do loop with large interation count X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "fxcoudert at gcc dot gnu dot org" 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: 2007-03/txt/msg02760.txt.bz2 $ cat a.f90 integer(kind=1) :: i integer(kind=8) :: c = 0 do i = -huge(i), huge(i), 2 c = c + 1 end do print *, c end $ gfortran a.f90 && ./a.out 0 I think it has to do with the comment on top of gfc_trans_do: TODO: Large loop counts The code above assumes the loop count fits into a signed integer kind, i.e. Does not work for loop counts > 2^31 for integer(kind=4) variables We must support the full range. Actually, I was looking at this code, saw the comment, and designed the testcase to trigger the bug :) It doesn't show up using a step of 1, because in that case we'd go into gfc_trans_simple_do. I think the loop count and other related quantities should be made unsigned, and the loop count should be changed from count = (to + step - from) / step to something else that cannot overflow. -- Summary: Wrong code for do loop with large interation count Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: fxcoudert at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31399