From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E41D93858C83; Wed, 11 Jan 2023 18:18:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E41D93858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673461084; bh=eLCBLwB6udu8UlHsnCPc5SUr4nF2mwBWzdvy95io16s=; h=From:To:Subject:Date:From; b=cIvzf5Rux/zu3l/ODbzJf0KROc4P745Gv8aF9yWyXyW3OsZamhf9poVCRFrtRcRCI iiW83XD1LttjGBqEvQxMSEpJObhMimcBmPDlCM7v8LEhpIXopLTNaXJRfFeYnbXQSC n+zW9KxE4AyGSZWI/S7YWAzMXI15ljZhVK9fqQ74= From: "romain.geissler at amadeus dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108374] New: [12/13 Regression] unexpected -Wstringop-overflow when using std::atomic and std::shared_ptr Date: Wed, 11 Jan 2023 18:18:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: romain.geissler at amadeus dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108374 Bug ID: 108374 Summary: [12/13 Regression] unexpected -Wstringop-overflow when using std::atomic and std::shared_ptr Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: romain.geissler at amadeus dot com Target Milestone: --- Hi, The following snippet produces an unexpected -Wstringop-overflow with gcc 12 and current trunk: #include #include struct A: public std::enable_shared_from_this { std::atomic _attr; }; void f(std::shared_ptr pointer) { std::weak_ptr weakPointer(pointer); [[maybe_unused]] const unsigned int aAttr =3D weakPointer.lock()->_attr; } Compiler Explorer output: In file included from /opt/compiler-explorer/gcc-trunk-20230111/include/c++/13.0.0/atomic:41, from :1: In member function 'std::__atomic_base<_IntTp>::__int_type std::__atomic_base<_IntTp>::load(std::memory_order) const [with _ITp =3D lo= ng unsigned int]', inlined from 'std::__atomic_base<_IntTp>::operator __int_type() const [= with _ITp =3D long unsigned int]' at /opt/compiler-explorer/gcc-trunk-20230111/include/c++/13.0.0/bits/atomic_ba= se.h:365:20, inlined from 'void f(std::shared_ptr)' at :13:69: /opt/compiler-explorer/gcc-trunk-20230111/include/c++/13.0.0/bits/atomic_ba= se.h:505:31: error: 'long unsigned int __atomic_load_8(const volatile void*, int)' writi= ng 8 bytes into a region of size 0 overflows the destination [-Werror=3Dstringop-overflow=3D] 505 | return __atomic_load_n(&_M_i, int(__m)); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ In function 'void f(std::shared_ptr)': cc1plus: note: destination object is likely at address zero cc1plus: some warnings being treated as errors Compiler returned: 1 I have found bug #104475 which seems to also deal with atomics and -Wstringop-overflow however I can't judge if it looks like a duplicate or a different issue. Cheers, Romain=