public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "J.K.Annot.at.Infor at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/47732] New: counter decremented to zero not detected when other counter overflows
Date: Mon, 14 Feb 2011 14:34:00 -0000	[thread overview]
Message-ID: <bug-47732-4@http.gcc.gnu.org/bugzilla/> (raw)

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");
}


             reply	other threads:[~2011-02-14 14:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-14 14:34 J.K.Annot.at.Infor at gmail dot com [this message]
2011-02-14 18:27 ` [Bug c/47732] " pinskia at gcc dot gnu.org
2011-02-15 14:25 ` J.K.Annot.at.Infor at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-47732-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).