From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E7603385840F; Sat, 12 Nov 2022 20:16:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E7603385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668284204; bh=6T9HE557DAWsVwz+6cerjr5xJzQ27tL9j4R1mUifnRw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ytJXIDM/LfzBrfp7JvQNxoHSCuWb5VlTH12DM/bE8l53/42Bgqll7TXiX2KofpTSm 6FeK7kjWo8Rpn9xBb0bhvM7oswSrShpzt0CIowD1A899K/IanTQBN+cRQMcEjZOWx1 3gspJlZmZrh+CWwlSxTvnLO5KjXNJF60j994oTLE= From: "slyfox at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/107661] [13 Regression] lambdas get merged incorrectly in tempaltes, cause llvm-12 miscompilation Date: Sat, 12 Nov 2022 20:16:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: needs-bisection, wrong-code X-Bugzilla-Severity: blocker X-Bugzilla-Who: slyfox at gcc dot gnu.org 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: 13.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created Message-ID: In-Reply-To: References: 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=3D107661 --- Comment #3 from Sergei Trofimovich --- Created attachment 53889 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53889&action=3Dedit a_simpler.cc a_simpler.cc is a bit more trimmed down version of a.cc: does not need prag= mas or argument forwarding. Uses only -O1 -fipa-cp -fipa-cp-clone: $ ./gcc-13-HEAD/bin/gcc -Wall -O1 -fipa-cp -fipa-cp-clone -DDISABLE_HACK a_simpler.cc -o a && ./a $ ./gcc-13-HEAD/bin/gcc -Wall -O1 -fipa-cp -fipa-cp-clone a_simpler.cc -o a= && ./a Illegal instruction (core dumped) /// 'function_ref' is taken from llvm-12 as is without any modifications. /// The rest if severely maimed AMDGCN hazard verifier code. // How to break: // $ ./gcc-13-snap/bin/gcc -O1 -fipa-cp -fipa-cp-clone=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20 a_simpler.cc -o a && ./a // Illegal instruction (core dumped) // $ ./gcc-13-snap/bin/gcc -O1 -fipa-cp -fipa-cp-clone -DDISABLE_HACK a_simpler.cc -o a && ./a // // #define DISABLE_HACK 1 #include class function_ref { void (*callback)(void * callable) =3D nullptr; void * callable; template static void callback_fn(void * callable) { (*reinterpret_cast(callable))(); } public: function_ref() =3D delete; template function_ref( Callable &&callable, // This is not the copy-constructor. std::enable_if_t< !std::is_same>, function_ref>::value> * =3D nullptr) : callback(callback_fn::type= >), callable(reinterpret_cast(&callable)) {} void operator()(void) const { callback(callable); } }; static int get_mbb_b(int MBB) { return MBB; } static int get_mbb_e(int MBB) { static int n =3D 0; switch (n++) { case 0: return MBB + 1; default: return MBB; } } static void getWaitStatesSince6(int MBB, int I, int WaitStates, function_ref Expired) { Expired(); if (I) { WaitStates +=3D 1; } auto pri =3D get_mbb_b(MBB); auto pre =3D get_mbb_e(MBB); if (pri !=3D pre) { getWaitStatesSince6(pri, I, WaitStates, Expired); } } static void getWaitStatesSince3(int MI, function_ref Expired) { getWaitStatesSince6(0, MI, 42, Expired); } static void always_void(void) { } int main() { getWaitStatesSince3(0, always_void); } #if defined(DISABLE_HACK) #else void seemingly_unused_foo(int MI) { struct L { void operator()(void) const { __builtin_trap(); } }; L IsExpiredFn; getWaitStatesSince3(MI, IsExpiredFn); } #endif=