public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51329] New: O3 optimizes away a loop
@ 2011-11-28  0:46 andrew.mcpherson at gmail dot com
  2011-11-28  1:12 ` [Bug c++/51329] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andrew.mcpherson at gmail dot com @ 2011-11-28  0:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51329

             Bug #: 51329
           Summary: O3 optimizes away a loop
    Classification: Unclassified
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: andrew.mcpherson@gmail.com


Created attachment 25923
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25923
preprocessor output

The following code generates the wrong exit code when compiled as follows:

/usr/bin/g++ -O3 -o bugexample bugexample.cpp

when compiled with O2, it works.  If a printf is placed in the right place it
also works.

Apologies to the lack of a simpler example, the bug disappears with small
changes.

g++ -v
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~123/src/configure --disable-checking
--enable-werror --prefix=/usr --mandir=/share/man
--enable-languages=c,objc,c++,obj-c++
--program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib
--build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10-
--host=x86_64-apple-darwin10 --target=i686-apple-darwin10
--with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)


#include <vector>
int test(std::vector<char>& a, int& b)
{
    std::vector<int> z;
    z.push_back(10);
    z.push_back(10);

    int d = (int)a.size();

    int x = 1;
    for (int j = 0; j < 2; j++)
    {
        int c = j - 1;

        for (int i = 0; i < d; i++) 
        {
            if (j == 0)
            {
            }
            else if (i == 0)
            {
            }
            else
            {
                if (a[j] == a[i - 1])
                {
                    b = c + 1;
                    x = 2;
                }
                z[i] = 1;
            }
        }
    }

    return x;
}


int main(int argc, char* argv[])
{
    std::vector<char> a;
    a.push_back('a');
    a.push_back('a');
    int b = 1;
    return test(a,b);
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/51329] O3 optimizes away a loop
  2011-11-28  0:46 [Bug c++/51329] New: O3 optimizes away a loop andrew.mcpherson at gmail dot com
@ 2011-11-28  1:12 ` pinskia at gcc dot gnu.org
  2011-11-28  7:51 ` andrew.mcpherson at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-11-28  1:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51329

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-11-28 00:20:21 UTC ---
First try to using a newer version of GCC, since 4.2.x is no longer supported. 
Also this is heavily modified version of 4.2.x from Apple so you should report
the bug report to them.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/51329] O3 optimizes away a loop
  2011-11-28  0:46 [Bug c++/51329] New: O3 optimizes away a loop andrew.mcpherson at gmail dot com
  2011-11-28  1:12 ` [Bug c++/51329] " pinskia at gcc dot gnu.org
@ 2011-11-28  7:51 ` andrew.mcpherson at gmail dot com
  2011-11-28 11:33 ` manu at gcc dot gnu.org
  2011-11-28 18:30 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: andrew.mcpherson at gmail dot com @ 2011-11-28  7:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51329

--- Comment #2 from Andrew <andrew.mcpherson at gmail dot com> 2011-11-28 06:45:29 UTC ---
Thanks, will report to apple.
(In reply to comment #1)
> First try to using a newer version of GCC, since 4.2.x is no longer supported. 
> Also this is heavily modified version of 4.2.x from Apple so you should report
> the bug report to them.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/51329] O3 optimizes away a loop
  2011-11-28  0:46 [Bug c++/51329] New: O3 optimizes away a loop andrew.mcpherson at gmail dot com
  2011-11-28  1:12 ` [Bug c++/51329] " pinskia at gcc dot gnu.org
  2011-11-28  7:51 ` andrew.mcpherson at gmail dot com
@ 2011-11-28 11:33 ` manu at gcc dot gnu.org
  2011-11-28 18:30 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2011-11-28 11:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51329

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-11-28 10:08:19 UTC ---
(In reply to comment #2)
> Thanks, will report to apple.

Reporting to Apple is useless, they have long moved to Clang, so they won't fix
bugs in GCC. By extension, advising someone to report GCC bugs to Apple is
doubly-useless. You are basically telling them "Forget about GCC, use Clang!"
because this is what Apple will tell them.

A better advice is to try to install a newer GCC on your own

http://gcc.gnu.org/install/

or using macports:

http://www.macports.org/install.php

I am sure you can find plenty of information on the net.

If the bug is still there, reopen this report.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/51329] O3 optimizes away a loop
  2011-11-28  0:46 [Bug c++/51329] New: O3 optimizes away a loop andrew.mcpherson at gmail dot com
                   ` (2 preceding siblings ...)
  2011-11-28 11:33 ` manu at gcc dot gnu.org
@ 2011-11-28 18:30 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-11-28 18:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51329

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-11-28 18:23:05 UTC ---
(In reply to comment #3)
> (In reply to comment #2)
> > Thanks, will report to apple.
> 
> Reporting to Apple is useless, they have long moved to Clang, so they won't fix
> bugs in GCC. By extension, advising someone to report GCC bugs to Apple is
> doubly-useless. You are basically telling them "Forget about GCC, use Clang!"
> because this is what Apple will tell them.
> 

Actually this is incorrect because Apple needs to know that a lot of folks
still use GCC and want to use GCC but that is all offtopic here really.  The
thing is that Apple supplied the GCC they are using and it is heavily modified
so Apple needs to support what they provided.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-11-28 18:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-28  0:46 [Bug c++/51329] New: O3 optimizes away a loop andrew.mcpherson at gmail dot com
2011-11-28  1:12 ` [Bug c++/51329] " pinskia at gcc dot gnu.org
2011-11-28  7:51 ` andrew.mcpherson at gmail dot com
2011-11-28 11:33 ` manu at gcc dot gnu.org
2011-11-28 18:30 ` pinskia at gcc dot gnu.org

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).