[Bug c++/104243] New: Optimization requires __sync_synchronize
aklitzing at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Jan 26 14:37:08 GMT 2022
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
More information about the Gcc-bugs
mailing list