From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BC5273858D35; Wed, 4 Jan 2023 13:05:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC5273858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672837536; bh=6CXUYoxX1NS5QTruB53a0cMALXLD8unlvAq4+Ovcpjw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ooMmm8Iwxb70/012KGFeJB3xeurVxV4eHi/tqg1bzifCg183R+rlYZY33WMAZoLax zbpEO8n1HkpKadaHunrRFWGALIFqc/8p+FdQzTGtqoVxcZNE/JAVLter2rRwNxkwfJ iS4Lrq8wVpoB6d+GLCXA2EJKYxbvMVQHYu9sAUqY= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108243] Missed optimization for static const std::string_view(const char*) Date: Wed, 04 Jan 2023 13:05:35 +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: 11.3.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi 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: 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=3D108243 --- Comment #1 from Jonathan Wakely --- This is caused by a change in libstdc++ headers: @@ -230,9 +230,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static _GLIBCXX_ALWAYS_INLINE constexpr bool __constant_string_p(const _CharT* __s) { +#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED + (void) __s; + // In constexpr contexts all strings should be constant. + return __builtin_is_constant_evaluated(); +#else while (__builtin_constant_p(*__s) && *__s) __s++; return __builtin_constant_p(*__s); +#endif } /** That affects the definition of std::char_traits::length: static constexpr size_t length(const char_type* __s) { if (__constant_string_p(__s)) return __gnu_cxx::char_traits::length(__s); return __builtin_strlen(__s); } So since GCC 9.1.0 we only treat the length as a constant expression if the string_view object is constexpr, otherwise we call strlen, which requires t= he object to exist. I think the compiler _should_ be able to optimize this case anyway, but may= be we need to partially revert the libstdc++ changes.=