From patchwork Sat Oct 15 10:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 2920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp587550wrs; Sat, 15 Oct 2022 03:52:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5T7F2d828PMsPhRhXMEJo3U/CYQxOiRPWjAafe0F4c7L0pIYpKjcW7aXEgOw5fH6UjVPcd X-Received: by 2002:aa7:d38f:0:b0:458:8d32:d642 with SMTP id x15-20020aa7d38f000000b004588d32d642mr1815109edq.208.1665831169795; Sat, 15 Oct 2022 03:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665831169; cv=none; d=google.com; s=arc-20160816; b=R6IwstPQD4Sqsr8jL32YenStz5RHe3MUBGsdhn4pz13w6ePzTwKECskMcY4OBZ1kut 9Fxue7PEQitzXqmMP3UMFzoInCx7e4sBIeWz4CshvYpDU739Osw1erOTy5aJppNinfi/ gOO4IlwO1h7hVh2E7I0I55r8VWzIF1EdjRPbDCk6+a458l+iU0F3nKg2lJr4AQd7RYcs rziUZ2sKX6l9cBnF2QwMWuXhccGM9oiBw5EHZvqy72HJKKmlL3Jb/QGGG6BaSYieMgf4 VZ/p+VUacUaNgq5crG7t7a7nAQQXGXo6nB/rwiz0HYIJBLacD7VwTVX9xs8BTCmoODfT sQ1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:references:in-reply-to:subject:to:from:ironport-sdr :dmarc-filter:delivered-to; bh=fyT8DxQkjXp3LmrXQWt2DPbRY8y+ahNcTbIqOJk4ZWA=; b=x0sU0Fb/8U9LtW05AwnKVwVYPW83K20qtp/JzqIiACPC+1cLJivFzMzt/KT+VXw0c5 Flwh2ufQi4nmaFpVUuidl5+xGhwoUBJYNmcupDXj4mItUKeS3IsBAPj+q9UVq+4dOJOK 6QknRBZ64sY5Ys5pjTwPpjdfIStoBJ2HOVx4ukQplsR7Omw2UTnh1IMxapSkscewBH2E t7cFiv6+OJadc/BKWH6/NnS45P+CJuD+ud13ohTLSzUL8fpEvy5mAmjptyox35OHfUiG ZUym2bWndIbd5h8uiqHOc4Q2X+sq0nF6SReA3Xw/zRJf11sSQocLMWtdYAv7tqPxjvVV /qZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id go38-20020a1709070da600b0078d8614e809si4770895ejc.504.2022.10.15.03.52.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Oct 2022 03:52:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A491385355D for ; Sat, 15 Oct 2022 10:52:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 5E5473858406; Sat, 15 Oct 2022 10:51:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E5473858406 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.95,186,1661846400"; d="scan'208,223";a="84778099" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 15 Oct 2022 02:51:52 -0800 IronPort-SDR: TZ3M/nRR+1DSHgX1sas5f1cL3DwIM7RuATagWMLM+B6hGOrCO+4/f4eTiRZLrCcl/Yt82xmfuJ 7cq6HaR0Ooi4AIU1KsdoVByPmMGNsmXG2YXz5s5wM92X2eGk1r6LAkyP6dHLHQh33RQfFil8/K z1LYDDMFfjzX5IszPSlTGm8JB6S55Cg/g30MlS6AfCPEFaf13FzQycCE3zE7McEg3TKJNX+9Ju 01Agy6o7cvM0xSaTRF0Nd2RSI2d6//0ueBSSwZJ5AgAjJ8cBUxLRZSdMqhxy46EWL2LdDX3b7E QyI= From: Thomas Schwinge To: Jonathan Wakely , , Subject: libstdc++: Address '-Wunused-function' for 'print_raw' (was: [committed] libstdc++: Simplify print_raw function for debug assertions) In-Reply-To: <20221014143602.2512815-1-jwakely@redhat.com> References: <20221014143602.2512815-1-jwakely@redhat.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Sat, 15 Oct 2022 12:51:44 +0200 Message-ID: <87sfjps6kf.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-13.mgc.mentorg.com (139.181.222.13) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746750584797889365?= X-GMAIL-MSGID: =?utf-8?q?1746750584797889365?= Hi! On 2022-10-14T15:36:02+0100, Jonathan Wakely via Gcc-patches wrote: > Tested powerpc64le-linux. Pushed to trunk. > > -- >8 -- > > Replace two uses of print_raw where it's clearer to just use fprintf > directly. Then the only remaining use of print_raw is as the print_func > argument of pretty_print. OK to push the attached "libstdc++: Address '-Wunused-function' for 'print_raw'", or should this be addressed differently? Grüße Thomas > When called by pretty_print the count is > either a positive integer or -1, so we can simplify print_raw itself. > > Remove the default argument, because it's never used. Remove the check > for nbc == 0, which never happens (but would be harmless if it did). > Replace the conditional expression with a single call to fprintf, using > INT_MAX as the maximum length. > > libstdc++-v3/ChangeLog: > > * src/c++11/debug.cc (print_raw): Simplify. > (print_word): Print indentation by calling fprintf directly. > (_Error_formatter::_M_error): Print unindented string by calling > fprintf directly. > --- > libstdc++-v3/src/c++11/debug.cc | 21 ++++++++------------- > 1 file changed, 8 insertions(+), 13 deletions(-) > > diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc > index abc4124c01e..f2b25fbefce 100644 > --- a/libstdc++-v3/src/c++11/debug.cc > +++ b/libstdc++-v3/src/c++11/debug.cc > @@ -37,6 +37,7 @@ > #include // for std::abort > #include // for std::isspace. > #include // for std::strstr. > +#include // for INT_MAX > > #include // for std::min. > > @@ -609,14 +610,11 @@ namespace > { print_word(ctx, word, Length - 1); } > > void > - print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc = -1) > + print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc) > { > - if (nbc != 0) > - { > - ctx._M_column += (nbc > 0) > - ? fprintf(stderr, "%.*s", (int)nbc, str) > - : fprintf(stderr, "%s", str); > - } > + if (nbc == -1) > + nbc = INT_MAX; > + ctx._M_column += fprintf(stderr, "%.*s", (int)nbc, str); > } > > void > @@ -645,12 +643,9 @@ namespace > || (ctx._M_column + visual_length < ctx._M_max_length) > || (visual_length >= ctx._M_max_length && ctx._M_column == 1)) > { > - // If this isn't the first line, indent > + // If this isn't the first line, indent. > if (ctx._M_column == 1 && !ctx._M_first_line) > - { > - const char spacing[PrintContext::_S_indent + 1] = " "; > - print_raw(ctx, spacing, PrintContext::_S_indent); > - } > + ctx._M_column += fprintf(stderr, "%*c", PrintContext::_S_indent, ' '); > > int written = fprintf(stderr, "%.*s", (int)length, word); > > @@ -1166,7 +1161,7 @@ namespace __gnu_debug > PrintContext ctx; > if (_M_file) > { > - print_raw(ctx, _M_file); > + ctx._M_column += fprintf(stderr, "%s", _M_file); > print_literal(ctx, ":"); > go_to_next_line = true; > } ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From 9ba7d0e6026ef4c3d095b0a57f9b88a87df403ea Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Sat, 15 Oct 2022 12:15:58 +0200 Subject: [PATCH] libstdc++: Address '-Wunused-function' for 'print_raw' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per recent commit r13-3303-gcf0b7e9787c3686c47219a725f2cbcaa19faaaca "libstdc++: Simplify print_raw function for debug assertions": > Replace two uses of print_raw where it's clearer to just use fprintf > directly. Then the only remaining use of print_raw is as the print_func > argument of pretty_print. But that one is only compiled '#if _GLIBCXX_HAVE_STACKTRACE'. In a '--enable-werror' build I've thus run into: [...]/source-gcc/libstdc++-v3/src/c++11/debug.cc:613:3: error: ‘void {anonymous}::print_raw(PrintContext&, const char*, ptrdiff_t)’ defined but not used [-Werror=unused-function] 613 | print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc) | ^~~~~~~~~ cc1plus: all warnings being treated as errors libstdc++-v3/ * src/c++11/debug.cc (print_raw): Only '#if _GLIBCXX_HAVE_STACKTRACE'. --- libstdc++-v3/src/c++11/debug.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index f2b25fbefce0..f62a1f755cf1 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -609,6 +609,7 @@ namespace print_literal(PrintContext& ctx, const char(&word)[Length]) { print_word(ctx, word, Length - 1); } +#if _GLIBCXX_HAVE_STACKTRACE void print_raw(PrintContext& ctx, const char* str, ptrdiff_t nbc) { @@ -616,6 +617,7 @@ namespace nbc = INT_MAX; ctx._M_column += fprintf(stderr, "%.*s", (int)nbc, str); } +#endif void print_word(PrintContext& ctx, const char* word, ptrdiff_t nbc = -1) -- 2.35.1