From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E0C533858D20; Mon, 20 May 2024 10:03:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0C533858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1716199404; bh=XvMTXBJa2qPT+0rZo6WBRtGoq8ClPDdcqswYifxPe/w=; h=From:To:Subject:Date:From; b=t2ZQbDwGuwkfw2bLEhN97I0XfVwm7IK1Juq349Vx8QxXXrKCiLnSUUUHEQ2cdrh1W SQ9lMwhzsHqLo8ylMED5r2QuWvasgjrcrjaBrjqU9VfhFEoW7akVgu+wCbDQ4r7p9N EzyImi1oz/dt5WUYMTQhuAtGIPHcDeX2UIn5H2CE= From: "raanan.lori at getnexar dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/115160] New: Enabling undefined behaviour sanitizer causes or'ed bit shift to report wrong result Date: Mon, 20 May 2024 10:03:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.4.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: raanan.lori at getnexar 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=3D115160 Bug ID: 115160 Summary: Enabling undefined behaviour sanitizer causes or'ed bit shift to report wrong result Product: gcc Version: 9.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: raanan.lori at getnexar dot com Target Milestone: --- I've tried to enable gcc undefined behaviour sanitizer recently and one of = my tests encountered an issue where bit shifts in certain code snippet will re= port a wrong result, i narrowed it down to this snippet. I used compiler explorer to find that the same behaviour is also in the lat= est release of gcc 14.4, tested with gcc 9.4 and 11.4 This was run under Unbuntu LTS 22.04 x86_64 My compile flags: `g++ -std=3Dc++17 -O0 -fsanitize=3Dundefined -Wall -fno-sanitize-recover main.cpp" The main.cpp code to replicate this issue: ``` #include #include #include int main() { std::vector data;=20=20=20=20 data.emplace_back(1); data.emplace_back(0); data.emplace_back(0); data.emplace_back(0); auto b =3D data.begin(); std::cout << (int)( (*b++) | (*b++ << 8) | (*b++ << 16 ) | ( *b << 24 ) )<< std::endl; return 0; } ``` expected output should be : 1 actual output: 256 note: no error or warning is produced for undefined behaviour=