public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104243] New: Optimization requires __sync_synchronize
@ 2022-01-26 14:37 aklitzing at gmail dot com
  2022-01-26 15:07 ` [Bug c++/104243] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: aklitzing at gmail dot com @ 2022-01-26 14:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104243

            Bug ID: 104243
           Summary: Optimization requires __sync_synchronize
           Product: gcc
           Version: 6.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aklitzing at gmail dot com
  Target Milestone: ---

Hi,

long time ago I found a strange behaviour with Qt and GCC 6.3. I tried it again
today with GCC 11.1.0.

If I compile this snippet with an optimization level it will output "broken".
If I use -O0 or use clang it will output "ok".
If I add "__sync_synchronize" it will work with any optimization, too. The
variable "idx" isn't updated in if-clause but it seems updated if qDebug is
called.


#include <QVersionNumber>
#include <QDebug>

int main(int argc, char** argv)
{
        const QString pVersion = QStringLiteral("1.12.2");
        int idx = 0;
        const auto& version = QVersionNumber::fromString(pVersion, &idx);

        // #ifdef Q_CC_GNU
        // __sync_synchronize();
        // #endif

        if(idx == 0)
                qDebug() << "broken";
        else
                qDebug() << "ok";

        qDebug() << "idx:" << idx;
        return 0;
}

$ g++ -O2 example.cpp `pkg-config --libs --cflags Qt5Core`
$ ./a.out
broken
idx: 6

$ g++ -O0 bla.cpp `pkg-config --libs --cflags Qt5Core`
$ ./a.out
ok
idx: 6


Source of QVersionNumber:
https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qversionnumber.cpp?h=5.15.2#n463

Qt-Report:
https://bugreports.qt.io/browse/QTBUG-62185

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

end of thread, other threads:[~2022-01-28  7:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 14:37 [Bug c++/104243] New: Optimization requires __sync_synchronize aklitzing at gmail dot com
2022-01-26 15:07 ` [Bug c++/104243] " rguenth at gcc dot gnu.org
2022-01-26 15:10 ` marxin at gcc dot gnu.org
2022-01-26 15:10 ` marxin at gcc dot gnu.org
2022-01-26 15:14 ` marxin at gcc dot gnu.org
2022-01-26 15:19 ` aklitzing at gmail dot com
2022-01-27  8:38 ` marxin at gcc dot gnu.org
2022-01-27 17:02 ` thiago at kde dot org
2022-01-27 17:33 ` marxin at gcc dot gnu.org
2022-01-28  7:39 ` rguenth 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).