From patchwork Tue Dec 20 10:49:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Arsen_Arsenovi=C4=87?= X-Patchwork-Id: 35029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2894450wrn; Tue, 20 Dec 2022 02:51:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf50+A2+OMLwrEI+EuzhdhWsA0P6cL2yCsM6Em4prBPfJbYeWToJGOqs6CDMK4LjDTBX4AYs X-Received: by 2002:a17:906:2442:b0:7ad:8f6f:806d with SMTP id a2-20020a170906244200b007ad8f6f806dmr37678238ejb.24.1671533475430; Tue, 20 Dec 2022 02:51:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671533475; cv=none; d=google.com; s=arc-20160816; b=sSMHpCJX15uE/6U5BnjOqo7jMlzPKk/ePQjOgzPrbaKiZEukawaNyGlUAeEr9Fdngc ThbGGMS/8DDv7r3ALqZsWH0m00907E8+KlpIR3/jgSsJaJuO6d+QIRWDRuK5gTkPjNHT yRepU0ioSGrRWeziIWbz1WCjflUhr33V6seRm9AnIxJYV/9VcrkspqeatjxImO6vWqR7 jIxB5xEsYKhaLV24KnAVgMpQV74FFJlhlvx7n/caQ/wLfDPipylWDSGPENVOmATkMmLK mb4IZknD/TEep3IYFHehRUg0RHmiV3BkTj/r9hd4vDtaCODzlfLGL/jot5ramA2DW2UC HPHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=0eQEFJ25R7m42N0TUhUQjTg3UmuDGy8M60f0zIwj4A0=; b=gwJpiBcaflWCS4X1w4qsi2yWCsDGTY6kr50lz4+p+Z4vZqB2tVEnqBYHZ53oDB4e5g XNC8z8/+oLMPJfCYf72jOMXf7RJ4Elu5mvVyaBGYfiIQDQmFq4ldd3hs1AcxfCepSFni DS6gb4tZtGr7Q9p9p1d3sRornd+P5oiTbVPSQozXmhsfpr7wjBIatPSn0yNQqmCU4u1F MbQW6GknAiZ1Bc1Qz+Tl5Yyd7EOexdon7BYvg7H43uSCSJ3KldCLQbfaB4ih0QXOiM8K Lcqy5gJBh2b4JirNmVLa2wFoiso8hKt/S6aVmi8/AJZfYZVnpiQoAFpEPXn8vCL/lunR 4jxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Urmvm4qJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s10-20020a170906c30a00b007c19ace9799si9425477ejz.952.2022.12.20.02.51.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 02:51:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Urmvm4qJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A846038493DF for ; Tue, 20 Dec 2022 10:50:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A846038493DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671533429; bh=0eQEFJ25R7m42N0TUhUQjTg3UmuDGy8M60f0zIwj4A0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Urmvm4qJVqK1olA6fzx6Z3Y4NWnCO9CidcovUTNYFjFJcoHLXyI8H/N2999fKjm31 Z9dkW7vU/iJFN/+90JWP+0oPg/1qbIvTMfdMaO+anOTGX8Mr4cEpiPPQ4KgUZ2AnK6 hLTrjW2eMdYxz44M/yco5SnrQ1U7hL1KNm/9HV1Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by sourceware.org (Postfix) with ESMTPS id 861F2385841D; Tue, 20 Dec 2022 10:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 861F2385841D Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Nbtcb1Vjxz9sZZ; Tue, 20 Dec 2022 11:49:35 +0100 (CET) To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, jwakely@redhat.com, libstdc++@gcc.gnu.org Subject: [PATCH 1/3] libstdc++: Improve output of default contract violation handler [PR107792] Date: Tue, 20 Dec 2022 11:49:14 +0100 Message-Id: <20221220104916.3000540-1-arsen@aarsen.me> In-Reply-To: <86ilictvdt.fsf@aarsen.me> References: <86ilictvdt.fsf@aarsen.me> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: =?utf-8?q?Arsen_Arsenovi=C4=87_via_Gcc-patches?= From: =?utf-8?q?Arsen_Arsenovi=C4=87?= Reply-To: =?utf-8?q?Arsen_Arsenovi=C4=87?= 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?1751820093635757471?= X-GMAIL-MSGID: =?utf-8?q?1752729885701775525?= From: Jonathan Wakely Make the output more readable. Don't output anything unless verbose termination is enabled at configure-time. libstdc++-v3/ChangeLog: PR libstdc++/107792 PR libstdc++/107778 * src/experimental/contract.cc (handle_contract_violation): Make output more readable. --- Alright, updated to omit information that's defaulted. Turns out your suggestion for dg-output was quite clever - because {} is special in ARE, it's always prefixed by \ when escaping with curlies, and so it never counds towards the "paired curly braces" rules, and requires no extra escaping code at all! That's quite a bit neater. libstdc++-v3/src/experimental/contract.cc | 50 ++++++++++++++++++----- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/src/experimental/contract.cc b/libstdc++-v3/src/experimental/contract.cc index c8d2697eddc..fbe8815a5c2 100644 --- a/libstdc++-v3/src/experimental/contract.cc +++ b/libstdc++-v3/src/experimental/contract.cc @@ -1,4 +1,5 @@ // -*- C++ -*- std::experimental::contract_violation and friends + // Copyright (C) 2019-2022 Free Software Foundation, Inc. // // This file is part of GCC. @@ -23,19 +24,46 @@ // . #include -#include +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE +# include +#endif __attribute__ ((weak)) void handle_contract_violation (const std::experimental::contract_violation &violation) { - std::cerr << "default std::handle_contract_violation called: \n" - << " " << violation.file_name() - << " " << violation.line_number() - << " " << violation.function_name() - << " " << violation.comment() - << " " << violation.assertion_level() - << " " << violation.assertion_role() - << " " << (int)violation.continuation_mode() - << std::endl; +#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE + bool level_default_p = violation.assertion_level() == "default"; + bool role_default_p = violation.assertion_role() == "default"; + bool cont_mode_default_p = violation.continuation_mode() + == std::experimental::contract_violation_continuation_mode::never_continue; + + const char* modes[]{ "never", "maybe" }; // Must match enumerators in header. + std::cerr << "contract violation in function " << violation.function_name() + << " at " << violation.file_name() << ':' << violation.line_number() + << ": " << violation.comment(); + + const char* delimiter = "\n["; + + if (!level_default_p) + { + std::cerr << delimiter << "level:" << violation.assertion_level(); + delimiter = ", "; + } + if (!role_default_p) + { + std::cerr << delimiter << "role:" << violation.assertion_role(); + delimiter = ", "; + } + if (!cont_mode_default_p) + { + std::cerr << delimiter << "mode:" + << modes[(int)violation.continuation_mode() & 1]; + delimiter = ", "; + } + + if (delimiter[0] == ',') + std::cerr << ']'; + + std::cerr << std::endl; +#endif } -