public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104475] New: Wstringop-overflow + atomics incorrect warning on dynamic object
@ 2022-02-09 19:37 thiago at kde dot org
  2022-02-09 20:14 ` [Bug tree-optimization/104475] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (28 more replies)
  0 siblings, 29 replies; 30+ messages in thread
From: thiago at kde dot org @ 2022-02-09 19:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104475
           Summary: Wstringop-overflow + atomics incorrect warning on
                    dynamic object
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thiago at kde dot org
  Target Milestone: ---

Created attachment 52399
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52399&action=edit
qfutureinterface.cpp preprocessed

In:
static inline int switch_on(QAtomicInt &a, int which)
{
    return a.fetchAndOrRelaxed(which) | which;
}

static inline int switch_off(QAtomicInt &a, int which)
{
    return a.fetchAndAndRelaxed(~which) & ~which;
}

void QFutureInterfaceBase::setThrottled(bool enable)
{
    QMutexLocker lock(&d->m_mutex);
    if (enable) {
        switch_on(d->state, Throttled);
    } else {
        switch_off(d->state, Throttled);
        if (!(d->state.loadRelaxed() & suspendingOrSuspended))
            d->pausedWaitCondition.wakeAll();
    }
}

Compiling the attached preprocessed sources with:

g++ -Wall -Wextra -march=haswell -O2 -c -o /dev/null qfutureinterface.cpp.ii

Produces:

In member function ‘std::__atomic_base<_IntTp>::__int_type
std::__atomic_base<_IntTp>::fetch_or(__int_type, std::memory_order) [with _ITp
= int]’,
    inlined from ‘static T QAtomicOps<X>::fetchAndOrRelaxed(std::atomic<T>&,
typename QAtomicAdditiveType<T>::AdditiveT) [with T = int; X = int]’ at
/home/tjmaciei/obj/qt/qt6/qtbase/include/QtCore/../../../../../../src/qt/qt6/qtbase/src/corelib/thread/qatomic_cxx11.h:449:33,
    inlined from ‘T QBasicAtomicInteger<T>::fetchAndOrRelaxed(T) [with T =
int]’ at
/home/tjmaciei/obj/qt/qt6/qtbase/include/QtCore/../../../../../../src/qt/qt6/qtbase/src/corelib/thread/qbasicatomic.h:168:36,
    inlined from ‘int switch_on(QAtomicInt&, int)’ at
/home/tjmaciei/src/qt/qt6/qtbase/src/corelib/thread/qfutureinterface.cpp:59:31,
    inlined from ‘void QFutureInterfaceBase::setThrottled(bool)’ at
/home/tjmaciei/src/qt/qt6/qtbase/src/corelib/thread/qfutureinterface.cpp:71:18:
/home/tjmaciei/dev/gcc/include/c++/12.0.1/bits/atomic_base.h:648:33: warning:
‘unsigned int __atomic_or_fetch_4(volatile void*, unsigned int, int)’ writing 4
bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
  648 |       { return __atomic_fetch_or(&_M_i, __i, int(__m)); }
      |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In member function ‘std::__atomic_base<_IntTp>::__int_type
std::__atomic_base<_IntTp>::fetch_and(__int_type, std::memory_order) [with _ITp
= int]’,
    inlined from ‘static T QAtomicOps<X>::fetchAndAndRelaxed(std::atomic<T>&,
typename QAtomicAdditiveType<T>::AdditiveT) [with T = int; X = int]’ at
/home/tjmaciei/obj/qt/qt6/qtbase/include/QtCore/../../../../../../src/qt/qt6/qtbase/src/corelib/thread/qatomic_cxx11.h:425:34,
    inlined from ‘T QBasicAtomicInteger<T>::fetchAndAndRelaxed(T) [with T =
int]’ at
/home/tjmaciei/obj/qt/qt6/qtbase/include/QtCore/../../../../../../src/qt/qt6/qtbase/src/corelib/thread/qbasicatomic.h:159:37,
    inlined from ‘int switch_off(QAtomicInt&, int)’ at
/home/tjmaciei/src/qt/qt6/qtbase/src/corelib/thread/qfutureinterface.cpp:64:32,
    inlined from ‘void QFutureInterfaceBase::setThrottled(bool)’ at
/home/tjmaciei/src/qt/qt6/qtbase/src/corelib/thread/qfutureinterface.cpp:73:19:
/home/tjmaciei/dev/gcc/include/c++/12.0.1/bits/atomic_base.h:638:34: warning:
‘unsigned int __atomic_fetch_and_4(volatile void*, unsigned int, int)’ writing
4 bytes into a region of size 0 overflows the destination
[-Wstringop-overflow=]
  638 |       { return __atomic_fetch_and(&_M_i, __i, int(__m)); }
      |                ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

GCC Git commit 1ce5395977f37e8d0c03394f7b932a584ce85cc7, built today.

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

end of thread, other threads:[~2023-09-18 10:04 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 19:37 [Bug c++/104475] New: Wstringop-overflow + atomics incorrect warning on dynamic object thiago at kde dot org
2022-02-09 20:14 ` [Bug tree-optimization/104475] [12 Regression] " pinskia at gcc dot gnu.org
2022-02-09 23:48 ` msebor at gcc dot gnu.org
2022-02-16 14:56 ` jakub at gcc dot gnu.org
2022-03-03 14:00 ` aldyh at gcc dot gnu.org
2022-03-03 16:09 ` amacleod at redhat dot com
2022-03-03 17:55 ` amacleod at redhat dot com
2022-03-04 14:47 ` amacleod at redhat dot com
2022-03-09 13:13 ` rguenth at gcc dot gnu.org
2022-03-12  9:39 ` aldyh at gcc dot gnu.org
2022-03-23 12:47 ` rguenth at gcc dot gnu.org
2022-03-23 17:23 ` aldyh at gcc dot gnu.org
2022-05-06  8:32 ` [Bug tree-optimization/104475] [12/13 " jakub at gcc dot gnu.org
2022-07-26 12:59 ` rguenth at gcc dot gnu.org
2022-12-05 15:50 ` rguenth at gcc dot gnu.org
2022-12-05 16:36 ` thiago at kde dot org
2022-12-06  8:17 ` rguenth at gcc dot gnu.org
2022-12-06  9:11 ` rguenth at gcc dot gnu.org
2022-12-06 10:22 ` cvs-commit at gcc dot gnu.org
2022-12-06 10:26 ` rguenth at gcc dot gnu.org
2022-12-06 18:03 ` thiago at kde dot org
2022-12-07  9:46 ` rguenth at gcc dot gnu.org
2022-12-07  9:48 ` rguenth at gcc dot gnu.org
2022-12-07  9:49 ` rguenth at gcc dot gnu.org
2022-12-07  9:54 ` rguenth at gcc dot gnu.org
2022-12-07 11:25 ` rguenth at gcc dot gnu.org
2023-01-17 17:37 ` jason at gcc dot gnu.org
2023-05-08 12:23 ` [Bug tree-optimization/104475] [12/13/14 " rguenth at gcc dot gnu.org
2023-09-18  9:19 ` aph at gcc dot gnu.org
2023-09-18 10:04 ` 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).