From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2047 invoked by alias); 14 Feb 2011 14:34:53 -0000 Received: (qmail 1701 invoked by uid 22791); 14 Feb 2011 14:34:52 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CX,TW_DC,TW_GC,TW_GX 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; Mon, 14 Feb 2011 14:34:46 +0000 From: "J.K.Annot.at.Infor at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/47732] New: counter decremented to zero not detected when other counter overflows X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: J.K.Annot.at.Infor at gmail dot com 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 Date: Mon, 14 Feb 2011 14:34:00 -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 X-SW-Source: 2011-02/txt/msg01678.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47732 Summary: counter decremented to zero not detected when other counter overflows Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: J.K.Annot.at.Infor@gmail.com Created attachment 23336 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23336 preprocessor output gcc version 4.3.3 [gcc-4_3-branch revision 147732] (SUSE Linux) Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-mtune=generic' /usr/lib64/gcc/x86_64-suse-linux/4.3/cc1 -E -quiet -v verify_counter_nonzero.c -mtune=generic -O2 -fpch-preprocess -o verify_counter_nonzero.i A local counter (named lCounter) is decremented in a while-loop, and the loop must stop when the counter reaches zero. In the same loop, a second local counter (lVeryHighCounter) is incremented and overflows in the same cycle where the first counter reaches zero. The overflow of the second counter seems to trigger that it is not detected that the first counter reaches zero: (lCounter != 0) remains false. A static counter (named sCounter) is used to observe what happens and to stop the program as soon as the bug is observed. The used -O2 option is needed to reproduce the bug. Using -O1 or -O3 does not reproduce the bug. extern int printf(const char *, ...); extern void exit(int); static int sCounter = 3; void verify_counter_nonzero( int aDummy ) { printf("sCounter value: %d\n", sCounter); if (sCounter == 0) { printf("Compiler bug detected! This function should not be called when counter reached 0.\n"); exit(0); } } int main() { int lCounter = 3; int lVeryHighCounter = 0x80000000 - 3; while (lCounter != 0) { verify_counter_nonzero(lVeryHighCounter); sCounter -= 1; lCounter -= 1; lVeryHighCounter += 1; /* In the same cycle where lCounter is decremented to 0, lVeryHighCounter is incremented (and overflows) from 0x7FFFFFFF to 0x80000000. This seems to trigger the bug: the loop condition (lCounter != 0) should become false, but remains true. */ } printf("Compiler bug not detected! Loop terminated correctly.\n"); }