From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 90C583858D32 for ; Wed, 28 Jun 2023 08:22:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90C583858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687940532; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iX0b08YmB7b2RKmRwZtcqDBGsByqvQL636J8ASxzmTM=; b=gJMdozrAI83PX6ChHN6XPNPemvnpvc4HrEvb107FNIajnOPwL4bMovlMuCJkw1q0dMc6Za IcthFFDc/KlNINhoU0hoO/v5qS26bDWrXR3dnl1HPLvhTnFcom/ZPSodtri1gh6IwOfb7V Cv/wUQHDQBaj8RJ0LHg0mdX+IEwvEfU= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-hWMMUlBrNNSExGaBQwhOBQ-1; Wed, 28 Jun 2023 04:22:09 -0400 X-MC-Unique: hWMMUlBrNNSExGaBQwhOBQ-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2b6c037f015so1416381fa.2 for ; Wed, 28 Jun 2023 01:22:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687940528; x=1690532528; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iX0b08YmB7b2RKmRwZtcqDBGsByqvQL636J8ASxzmTM=; b=hSa7NZ6tmnFvHcvLdqFdY+A0CPaYOoU3lWLA2MV5WmrXugeReN4sGHsb5j6beLzC9k XeVcUU4HoAKJxHq3iFg6b/NlbN3zXFjZlN2rG1cabQ3dRAxY6mhzIN3V3izCjTHjZhss insVFY0LWwQehgUW5+bjp3S85q8VDt1mAujRtcuOXqgak+T3L6wJFNIvgXYWW2Q0/47a ucHkh6J2BPnQ6FJEQxCEW7OjDy1xvhacJ7zYyOmrYXf+2u9MTZszkItu48lSZ+N67q52 aPQqaRWSfHabKVs6PH11vjg3OXbiqKJsoYP2a6IzQ2pQyH+VTcrGMt0tX3simraqdmp/ uMeQ== X-Gm-Message-State: AC+VfDyfYrUnzsmoVZ3wMneB4Z+8I3X1DCndKOh85cYnB6kE9KNhZYx2 gXKsuGE97D8GtqcwGlTsSamFjcEp3LBMtvVDpUvNkDlOCktAhav4nCa73f7XoG1kFtyHeKiQGQr y6EEJmddMk6hrYwax480QgegVT/7y9EQ= X-Received: by 2002:a2e:8702:0:b0:2b4:7f2e:a433 with SMTP id m2-20020a2e8702000000b002b47f2ea433mr21066224lji.36.1687940528534; Wed, 28 Jun 2023 01:22:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7yssin+psDq/zFeR9vJomtDV+4fi6/hQ6KxUQyD6k/pqOU/S3E8D4IzY/jCHm9utTUkcpXV4QXmfgTTcp0i+s= X-Received: by 2002:a2e:8702:0:b0:2b4:7f2e:a433 with SMTP id m2-20020a2e8702000000b002b47f2ea433mr21066197lji.36.1687940528105; Wed, 28 Jun 2023 01:22:08 -0700 (PDT) MIME-Version: 1.0 References: <20230620133858.166497-1-jwakely@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Wed, 28 Jun 2023 09:21:56 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Use RAII in std::vector::_M_realloc_insert To: Jan Hubicka Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="00000000000094832d05ff2c47b7" X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --00000000000094832d05ff2c47b7 Content-Type: text/plain; charset="UTF-8" On Wed, 28 Jun 2023 at 08:56, Jan Hubicka wrote: > > I think the __throw_bad_alloc() and __throw_bad_array_new_length() > > functions should always be rare, so marking them cold seems fine (users > who > > define their own allocators that want to throw bad_alloc "often" will > > probably throw it directly, they shouldn't be using our > __throw_bad_alloc() > > function anyway). I don't think __throw_bad_exception is ever used, so > that > > doesn't matter (we could remove it from the header and just keep its > > definition in the library, but there's no big advantage to doing that). > > Others like __throw_length_error() should also be very very rare, and > could > > be marked cold. > > > > Maybe we should just mark everything in as cold. If > > users want to avoid the cost of calls to those functions they can do so > by > > checking function preconditions/arguments to avoid the exceptions. There > > are very few places where a throwing libstdc++ API doesn't have a way to > > avoid the exception. The only one that isn't easily avoidable is > > __throw_bad_alloc but OOM should be rare. > > Hi, > this marks everything in functexcept.h as cold and I also noticed that > we probably want to mark as such terminate. > > With fix to 110436 and -O3 we now inline _M_realloc_insert, yay :) > > tested on x86_64-linux, OK? > OK for trunk, thanks. > > * include/bits/c++config (std::__terminate): Mark cold. > * include/bits/functexcept.h: Mark everything as cold. > * libsupc++/exception: Mark terminate and unexpected as cold. > diff --git a/libstdc++-v3/include/bits/c++config > b/libstdc++-v3/include/bits/c++config > index 009a017b048..dd47f274d5f 100644 > --- a/libstdc++-v3/include/bits/c++config > +++ b/libstdc++-v3/include/bits/c++config > @@ -320,7 +320,7 @@ namespace std > extern "C++" __attribute__ ((__noreturn__, __always_inline__)) > inline void __terminate() _GLIBCXX_USE_NOEXCEPT > { > - void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__)); > + void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ > ((__noreturn__,__cold__)); > terminate(); > } > #pragma GCC visibility pop > diff --git a/libstdc++-v3/include/bits/functexcept.h > b/libstdc++-v3/include/bits/functexcept.h > index 2765f7865df..a2e97413661 100644 > --- a/libstdc++-v3/include/bits/functexcept.h > +++ b/libstdc++-v3/include/bits/functexcept.h > @@ -57,61 +57,61 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > // Helper for exception objects in > void > - __throw_bad_cast(void) __attribute__((__noreturn__)); > + __throw_bad_cast(void) __attribute__((__noreturn__,__cold__)); > > void > - __throw_bad_typeid(void) __attribute__((__noreturn__)); > + __throw_bad_typeid(void) __attribute__((__noreturn__,__cold__)); > > // Helpers for exception objects in > void > - __throw_logic_error(const char*) __attribute__((__noreturn__)); > + __throw_logic_error(const char*) __attribute__((__noreturn__,__cold__)); > > void > - __throw_domain_error(const char*) __attribute__((__noreturn__)); > + __throw_domain_error(const char*) > __attribute__((__noreturn__,__cold__)); > > void > - __throw_invalid_argument(const char*) __attribute__((__noreturn__)); > + __throw_invalid_argument(const char*) > __attribute__((__noreturn__,__cold__)); > > void > - __throw_length_error(const char*) __attribute__((__noreturn__)); > + __throw_length_error(const char*) > __attribute__((__noreturn__,__cold__)); > > void > - __throw_out_of_range(const char*) __attribute__((__noreturn__)); > + __throw_out_of_range(const char*) > __attribute__((__noreturn__,__cold__)); > > void > - __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__)) > + __throw_out_of_range_fmt(const char*, ...) > __attribute__((__noreturn__,__cold__)) > __attribute__((__format__(__gnu_printf__, 1, 2))); > > void > - __throw_runtime_error(const char*) __attribute__((__noreturn__)); > + __throw_runtime_error(const char*) > __attribute__((__noreturn__,__cold__)); > > void > - __throw_range_error(const char*) __attribute__((__noreturn__)); > + __throw_range_error(const char*) __attribute__((__noreturn__,__cold__)); > > void > - __throw_overflow_error(const char*) __attribute__((__noreturn__)); > + __throw_overflow_error(const char*) > __attribute__((__noreturn__,__cold__)); > > void > - __throw_underflow_error(const char*) __attribute__((__noreturn__)); > + __throw_underflow_error(const char*) > __attribute__((__noreturn__,__cold__)); > > // Helpers for exception objects in > void > - __throw_ios_failure(const char*) __attribute__((__noreturn__)); > + __throw_ios_failure(const char*) __attribute__((__noreturn__,__cold__)); > > void > - __throw_ios_failure(const char*, int) __attribute__((__noreturn__)); > + __throw_ios_failure(const char*, int) > __attribute__((__noreturn__,__cold__)); > > // Helpers for exception objects in > void > - __throw_system_error(int) __attribute__((__noreturn__)); > + __throw_system_error(int) __attribute__((__noreturn__,__cold__)); > > // Helpers for exception objects in > void > - __throw_future_error(int) __attribute__((__noreturn__)); > + __throw_future_error(int) __attribute__((__noreturn__,__cold__)); > > // Helpers for exception objects in > void > - __throw_bad_function_call() __attribute__((__noreturn__)); > + __throw_bad_function_call() __attribute__((__noreturn__,__cold__)); > > #else // ! HOSTED > > diff --git a/libstdc++-v3/libsupc++/exception > b/libstdc++-v3/libsupc++/exception > index a34386e6026..00a6347ebe5 100644 > --- a/libstdc++-v3/libsupc++/exception > +++ b/libstdc++-v3/libsupc++/exception > @@ -75,7 +75,7 @@ namespace std _GLIBCXX_VISIBILITY(default) > > /** The runtime will call this function if %exception handling must be > * abandoned for any reason. It can also be called by the user. */ > - void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__)); > + void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ > ((__noreturn__,__cold__)); > > #if __cplusplus < 201703L || (__cplusplus <= 202002L && > _GLIBCXX_USE_DEPRECATED) > /// If you write a replacement %unexpected handler, it must be of this > type. > @@ -104,7 +104,7 @@ namespace std _GLIBCXX_VISIBILITY(default) > * @deprecated Removed from the C++ standard in C++17 > */ > _GLIBCXX11_DEPRECATED > - void unexpected() __attribute__ ((__noreturn__)); > + void unexpected() __attribute__ ((__noreturn__,__cold__)); > #endif > > /** [18.6.4]/1: 'Returns true after completing evaluation of a > > --00000000000094832d05ff2c47b7--