From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C91513858410; Fri, 17 Mar 2023 10:12:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C91513858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679047975; bh=J9kIQoS6KOIs3dbUHmmz99saO0MgogMqghgbZvhFUhI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lOzrp3w8J65qgggh8RK6e1U7Ln6hXBrSHQmjpejcw80nryaybK8Fz1KTeGyORv1MS TWcnUCY//YIS5LoUz1YIBWJfbKlKoi0jiwI/4RCBWe/HaMqhc3FINqIOl+1UufPghM NjPyGSkFTeDWtmPipcTx94PDR48yVgW7XC+TKOK4= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109164] wrong code with thread_local reference, loops and -ftree-pre Date: Fri, 17 Mar 2023 10:12:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: component cc 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=3D109164 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Component|tree-optimization |c++ CC| |jason at gcc dot gnu.org --- Comment #4 from Richard Biener --- So we have ;; Function Struct& _ZTW16thread_local_ref() (null) ;; enabled by -tree-original if (_ZTH16thread_local_ref !=3D 0B) { <>>>>; } return =3D thread_local_ref; which is eventually inlined. But 'thread_local_ref' is TREE_READONLY and thus may_be_aliased is false and the readonly-global exception triggers: /* If the reference is based on a decl that is not aliased the call cannot possibly clobber it. */ if (DECL_P (base) && !may_be_aliased (base) /* But local non-readonly statics can be modified through recursion or the call may implement a threading barrier which we must treat as may-def. */ && (TREE_READONLY (base) || !is_global_var (base))) return false; I think it's a mistake for the frontend to set TREE_READONLY on the decl if it requires initialization (we've been there for other runtime initialized globals). Thus -> C++ FE bug.=