From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by sourceware.org (Postfix) with ESMTPS id EF433385800F for ; Wed, 31 Aug 2022 21:00:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF433385800F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vvalter.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vvalter.com Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 205AF32001C6 for ; Wed, 31 Aug 2022 17:00:10 -0400 (EDT) Received: from imap47 ([10.202.2.97]) by compute5.internal (MEProxy); Wed, 31 Aug 2022 17:00:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vvalter.com; h= cc:content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t= 1661979609; x=1662066009; bh=XJsiwNxNJlxFMLsVqrRYEwthFevk40jMc3p p4hzFmZQ=; b=clUA+FOsZrfjMSVFWrq2Tou+pbx6ayE0X4WhmL1aLsvcEh0C8ZP pe/GhPOrz4ORkolNEIolTu5quIzWVUVN5vil7+NiJBuN+Xb7YFu0+ZsHg73r2z89 VPSR+WtExA8xHjHBb/hZxhUDiOM/RLgw2IA1R7KA/BPDvcA5esmlUQ6nhSBgEOQp bPktNFtpbcQuG7xQ7u0XXHkNli95OHIiE+ZZpuujzrFv2qJ+GMl9SrnZZw3Oh3iT xLi2zcG/ige3pVsSUyOYppUsHcpMI60TEIjQfwS08Tmmy6wnaFq4H1S7lwBufix7 wmTPozbjz02kAOa/84KCcclzXgh8Fw0AmsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1661979609; x= 1662066009; bh=XJsiwNxNJlxFMLsVqrRYEwthFevk40jMc3pp4hzFmZQ=; b=w sUvo0vWecZ0yXJGR08PyINq9d8olNRsMJPWn6e9q5Kb+E73kOKCXqlOu+rS/7P1Q jXvZZ1Ggi0cZz1c+s92+uyAhSsTRiGqUSvdzLbmX0RzwvZKN4YrlJJrgACalq21X 55BXi4rOZywXjqXOkSqan4uwq+ZRQXenYehObbUhtY46UBBnhJpHtyxLW9WQ42q8 2B9pHBp4OJkPIDloLXWP5tUeLt3TmmaX77BLhr/RdRNXKmsMIRtXbvJmVf3zBD0i cvs8lysJUs5cFKxOseoy5vPuQ8J7dNp7pu8QGsD/Q/Pw6UvC+lVS1NVoTw52qi1G e4/y1AOsC0CiOD5PtNrSQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdekiedguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkfffhvffutgesthdtre dtreertdenucfhrhhomhepfdfuihhmohhnucftrghinhgvrhdfuceoghgttgdrghhnuhes vhhvrghlthgvrhdrtghomheqnecuggftrfgrthhtvghrnhepjeelgfeghefgheeludeuje dtudegtedtjeeghfeiheffheevtdffhfffudehveevnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomhepghgttgdrghhnuhesvhhvrghlthgvrhdrtg homh X-ME-Proxy: Feedback-ID: ibff947e6:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4839BA6007C; Wed, 31 Aug 2022 17:00:09 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-841-g7899e99a45-fm-20220811.002-g7899e99a Mime-Version: 1.0 Message-Id: <5d937aa3-c33d-4ade-8b7e-9fd0effd147d@www.fastmail.com> Date: Wed, 31 Aug 2022 23:00:08 +0200 From: "Simon Rainer" To: gcc-patches@gcc.gnu.org Subject: [PATCH] ipa: Fix throw in multi-versioned functions [PR106627] Content-Type: text/plain X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, This patch fixes PR106627. I ran the i386.exp tests on my x86_64-linux-gnu machine with a fully bootstrapped checkout. I also tested manually that no exception handling code is generated if none of the function versions throws an exception. I don't have access to a machine to test the change to rs6000.cc, but the code seems like an exact copy and I don't see a reason why it shouldn't work there the same way. Regards Simon Rainer >From 6fcb1c742fa1d61048f7d63243225a8d1931af4a Mon Sep 17 00:00:00 2001 From: Simon Rainer Date: Wed, 31 Aug 2022 20:56:04 +0200 Subject: [PATCH] ipa: Fix throw in multi-versioned functions [PR106627] Any multi-versioned function was implicitly declared as noexcept, which leads to an abort if an exception is thrown inside the function. The reason for this is that the function declaration is replaced by a newly created dispatcher declaration, which has TREE_NOTHROW always set to 1. Instead we need to set TREE_NOTHROW to the value of the original declaration. PR ipa/106627 gcc/ChangeLog: * config/i386/i386-features.cc (ix86_get_function_versions_dispatcher): Set TREE_NOTHROW correctly for dispatcher declaration * config/rs6000/rs6000.cc (rs6000_get_function_versions_dispatcher): Likewise gcc/testsuite/ChangeLog: * g++.target/i386/pr106627.C: New test. --- gcc/config/i386/i386-features.cc | 1 + gcc/config/rs6000/rs6000.cc | 1 + gcc/testsuite/g++.target/i386/pr106627.C | 30 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/g++.target/i386/pr106627.C diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index d6bb66cbe01..5b3b1aeff28 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -3268,6 +3268,7 @@ ix86_get_function_versions_dispatcher (void *decl) /* Right now, the dispatching is done via ifunc. */ dispatch_decl = make_dispatcher_decl (default_node->decl); + TREE_NOTHROW(dispatch_decl) = TREE_NOTHROW(fn); dispatcher_node = cgraph_node::get_create (dispatch_decl); gcc_assert (dispatcher_node != NULL); diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 2f3146e56f8..9280da8a5c8 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -24861,6 +24861,7 @@ rs6000_get_function_versions_dispatcher (void *decl) /* Right now, the dispatching is done via ifunc. */ dispatch_decl = make_dispatcher_decl (default_node->decl); + TREE_NOTHROW(dispatch_decl) = TREE_NOTHROW(fn); dispatcher_node = cgraph_node::get_create (dispatch_decl); gcc_assert (dispatcher_node != NULL); diff --git a/gcc/testsuite/g++.target/i386/pr106627.C b/gcc/testsuite/g++.target/i386/pr106627.C new file mode 100644 index 00000000000..a67f5ae4813 --- /dev/null +++ b/gcc/testsuite/g++.target/i386/pr106627.C @@ -0,0 +1,30 @@ +/* PR c++/103012 Exception handling with multiversioned functions */ +/* { dg-do run } */ +/* { dg-require-ifunc "" } */ + +#include + +__attribute__((target("default"))) +void f() { + throw 1; +} + +__attribute__((target("sse4.2,bmi"))) +void f() { + throw 2; +} + +int main() +{ + try { + f(); + } + catch(...) + { + return 0; + } + + assert (false); + return 1; +} + -- 2.34.1