From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 5D03B3858289 for ; Fri, 2 Sep 2022 06:03:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D03B3858289 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x636.google.com with SMTP id og21so1809132ejc.2 for ; Thu, 01 Sep 2022 23:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=GfHyxkxcH+eTILoFzCIDGwMSt7Wi/PKiyMFokE+vI0I=; b=EkGvMLVGhFZeiIpdqxbFkd57xsEnPfn5GdG3hnahwsHi1Xk4HB8zPuqynD0iMMuhIn gYvOSR1JLBGFscbtPTLIW13IXveBeYF4+PXYjVYyMkBN3wl/uNHzPDHCBFEw2XpKZlyO hqBtUVYZElJSGpOuyy3HGaePUtq8nKelpPE0SE5Q9F1WPd0QpCx5iTtZPJ7J63Bg0hwL 8JzvopjG+cHRH4Y43P51d9L4oC8TnycMuHpZ3xvOP95T2kj9kMnAW2W+fzLcBhZB7foQ 9aH74547TObFdW1k3nfhp4MFoALu4iyh8wp7S2lU4dmphsq0zmsdgfFkR7e5X+Lovnfe VE/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=GfHyxkxcH+eTILoFzCIDGwMSt7Wi/PKiyMFokE+vI0I=; b=o1KOnmYK2ieA6rMV57Ysz2kCENcl7esGLQeL6KeUDbGhMDep9587XtGNzxcgSJv/aN u564IQeUXZ/I55/0PBYntSV/7+4s7lWKP6CUlGB/wdNUfLzUVWkuLjq7KZNuGO0YrZQZ 93ca3Gh+GCFfkWgYrQKE9blSMXYOJgVxF0kfMHvVQBA5b3vOT5Lt7DXWGCPuYULDa2rW HFZERJ9ZPUsHA3NivNbM/Ra4OhtpYaL74BY4x0VOHrh7B9NxForbRZ1tZebPT4/OVREr BpfETfjnoF1su/ZwxbhYD3kcjphtHJ7JVg1cTxYtH9/zMSn0GpHuh1NhC16fJh9uGM+r ccvw== X-Gm-Message-State: ACgBeo1U0HDFdr4G5Ze3+z96ffhzTsC/0BX/KbwkvE8QsVplCx2V0rA2 Nvrd0WcsBdB4xMgZ7RSGVh9t4RR5YxMNUV8EcpE= X-Google-Smtp-Source: AA6agR40pIlOcS+zE+3Cb3GSB/kDU8xAm0y1XxADXWYbJN1QNguWVzX+HcvAWeYYY5XprfTfaPwWWcA48wfxk1Znxbo= X-Received: by 2002:a17:906:5d16:b0:74c:32ce:208b with SMTP id g22-20020a1709065d1600b0074c32ce208bmr2843369ejt.594.1662098618607; Thu, 01 Sep 2022 23:03:38 -0700 (PDT) MIME-Version: 1.0 References: <5d937aa3-c33d-4ade-8b7e-9fd0effd147d@www.fastmail.com> <364ad037-a4fc-409e-b76c-b9c3bf9b94ed@www.fastmail.com> In-Reply-To: <364ad037-a4fc-409e-b76c-b9c3bf9b94ed@www.fastmail.com> From: Richard Biener Date: Fri, 2 Sep 2022 08:03:26 +0200 Message-ID: Subject: Re: [PATCH] ipa: Fix throw in multi-versioned functions [PR106627] To: Simon Rainer Cc: Jan Hubicka , GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: On Thu, Sep 1, 2022 at 7:51 PM Simon Rainer wrote: > > Hi, > > Thanks for taking a look at my patch. I tested some combinations with pure/noreturn attributes. gcc seems to ignore those attributes on multiversion functions and generates sub-optimal assembly. > But I wasn't able to fix this by simply copying members like DECL_PURE_P. It's pretty hard for me to tell which members of tree are relevant for a function declaration and should be copied and which should not be copied. > > Anyway, I think the TREE_NOTHROW change is the most important one, because it leads to correctness problems (and is what broke my original program :D ), so could you please commit my patch as I don't have write-access myself. Sure, will do - thanks for the fix! > > Should I open a new bug on bugzilla for the pure/noreturn issue? Yes, I think it's worth investigating. Richard. > Thanks > Simon Rainer > > > On Thu, Sep 1, 2022, at 08:37, Richard Biener wrote: > > On Wed, Aug 31, 2022 at 11:00 PM Simon Rainer wrote: > > > > > > 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. > > > > Looks quite obvious. The middle-end to target interface is a bit iffy > > since we have > > to duplicate this everywhere. There's also other flags like > > pure/const and noreturn > > that do not impose correctness issues but may cause irritations if the IL gets > > a call to the dispatcher not marked noreturn but there's no code following. > > > > That said, the fix looks good to me. > > > > Thanks, > > Richard. > > > > > 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 > > > > >