From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0E852384B801; Fri, 11 Jun 2021 09:02:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E852384B801 From: "alois1@gmx-topmail.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101027] New: Short-circuit behavior not respected with co_await in while head Date: Fri, 11 Jun 2021 09:02:07 +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: 11.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alois1@gmx-topmail.de 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 attachments.created 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Jun 2021 09:02:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101027 Bug ID: 101027 Summary: Short-circuit behavior not respected with co_await in while head Product: gcc Version: 11.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: alois1@gmx-topmail.de Target Milestone: --- Created attachment 50983 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50983&action=3Dedit Reduced preprocessed code GCC miscompiles the following C++ program: $ cat test.cpp #include struct task { struct promise_type { task get_return_object() { return {std::coroutine_handle::from_promise(*this)}; } std::suspend_never initial_suspend() { return {}; } std::suspend_never final_suspend() noexcept { return {}; } void unhandled_exception() {} void return_void() {} }; bool await_ready() { return true; } void await_suspend(std::coroutine_handle<>) {} bool await_resume() { return true; } std::coroutine_handle m_handle; }; extern "C" void exit(int status); task should_not_execute() { exit(1); co_return; } task main_task() { while (false && co_await should_not_execute()); } int main() { main_task(); } $ gcc -v Using built-in specs. COLLECT_GCC=3D/usr/bin/gcc COLLECT_LTO_WRAPPER=3D/usr/lib64/gcc/x86_64-suse-linux/11/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-suse-linux Configured with: ../configure --prefix=3D/usr --infodir=3D/usr/share/info --mandir=3D/usr/share/man --libdir=3D/usr/lib64 --libexecdir=3D/usr/lib64 --enable-languages=3Dc,c++,objc,fortran,obj-c++,ada,go,d,jit --enable-offload-targets=3Dnvptx-none,amdgcn-amdhsa, --without-cuda-driver --enable-host-shared --enable-checking=3Drelease --disable-werror --with-gxx-include-dir=3D/usr/include/c++/11 --enable-ssp --disable-libssp --disable-libvtv --enable-cet=3Dauto --disable-libcc1 --enable-plugin --with-bugurl=3Dhttps://bugs.opensuse.org/ --with-pkgversion=3D'SUSE Linux' --with-slibdir=3D/lib64 --with-system-zlib --enable-libstdcxx-allocator=3Dn= ew --disable-libstdcxx-pch --enable-libphobos --enable-version-specific-runtime-libs --with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function --program-suffix=3D-11 --without-system-libunwind --enable-multilib --with-arch-32=3Dx86-64 --with-tune=3Dgeneric --with-build-config=3Dbootstrap-lto-lean --enable-link-mutex --build=3Dx86_64-suse-linux --host=3Dx86_64-suse-linux Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.1.1 20210510 [revision 23855a176609fe8dda6abaf2b21846b451796= 6eb] (SUSE Linux)=20 $ g++ -std=3Dc++20 test.cpp; ./a.out; echo $? 1 Expected output would be 0, as the && operator should short-circuit, and should_not_execute therefore should never be started (in particular, the ca= ll to exit should not be reached). Interestingly, the unexpected behavior only happens in a while head, in an = if head or assignment to a variable the short-circuit behavior seems to be respected. For convenience, I have attached a manually reduced version of the preproce= ssed code that I have confirmed to exhibit the same behavior.=