From patchwork Tue Apr 9 15:46:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88253 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 180FA385828B for ; Tue, 9 Apr 2024 15:46:51 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by sourceware.org (Postfix) with ESMTPS id 9F900385841C for ; Tue, 9 Apr 2024 15:46:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F900385841C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9F900385841C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712677589; cv=none; b=T8w7MjRE+3GEtKG5OAud6Nyk3OfLLHDrM3HYuD6Tm31PeUPgvaw5UwWe6V14OPe36Jv8P3BaXY6iVwA2fSex1q08PjFOyp5zMLx7+0x8I5jQcqhi62jUlM9KmDlZEzeIwcctMiXcNLiF0EkPvyiiYCwt00uUspIDRnaYnpfqPB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712677589; c=relaxed/simple; bh=XWRL7H7oG7grgMsUI7i84JgItV/n9voXTKfwp4W3sik=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qxed7HiUZHlHQi0piwo7Q/SA7Y1VqYyqoUtlpnUuQ3jim65URSi/zH0B73+aMWNKmczJYVSHdfTscfWPpkyCBXBGKI61qTIf82upFLHK0FoGYnwLxBOWilmx+UjBHPa+gZlqn6KgohIZHsyIDNTt5+aSsXL6kpcbqqSBpBSmSvg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7d03a6a11a2so260632339f.2 for ; Tue, 09 Apr 2024 08:46:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1712677585; x=1713282385; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dMzNnBdNHuEE4SFiYI3A/QP6gh833xXGrfIsDkxhbU4=; b=HXGeu+wqgzf7y62a5HR6Di3xHpAEL/DZ/XliV7eFLFqxJ0bzMyfomF0pWl/T5AGQiy K18Oc0cR/RwrXXqocpZatJ14fxJrqMjEkCVzIGOm90HEwJ/LFuDWYKFKB4WsZ5HaB+QO OdyyNnrijGkvryhED2/wFYM21wpYOntXVe4Xi4n7b2CIdyRWUh39I4j/A6+tefHAqr5u ur51x/wbRUa+Sl+P5oJlJ96s0GtNPhst1X00pjjam40FW2kVbSTrRIvzrIiwD4r2+apc TlHCYuPsZnVZ2X/8AwvH7cg0a4BrU1It0+W/DdhRuAnaSUlt/JsExNT7chOxKaBt/fKG /EVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712677585; x=1713282385; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dMzNnBdNHuEE4SFiYI3A/QP6gh833xXGrfIsDkxhbU4=; b=UJQZVLIh9oRTmVmPggAbp3ggXsUfwEz60ycrr3MZrbQV/pyTxaMcpQ9pJBsNk9YbD0 7UqxEZ/E9ZT3WNX/UUxukjbcOGB10/07F3Rx+5ywHRJ/7hdT0fHvrhFIe5NNhOZSprDH 8dBEWY9j4mZj/srauhAAlezCqovtPktSXAtvvrmfISv3bsheU3lPSCE6jUukCZh7GaMe K+LQbNIzRr7x97BoJ0Eu9kPkXTqHQwKq5Dybjsl9u7jRc664WoW+0XJaaB3u6X09Khx3 CdbprB9aYJruNrKuLcrV4L5a/JaBT2YMdFPorUa/1SLJsf0nZu+W6/DX+S4mt3HhiwMN aAJQ== X-Gm-Message-State: AOJu0Yz5KBDrsUkACw0oCCrpZ/dMEAwD1RqjogmJ0HacjLHQMsGWgkWH /DcPCzLB26ggM3zDAZTEikAmaS5n7JXBYGWxUpvnFfGscb9dGLPbowZnLoJEfZvugTEH4xv8/AA = X-Google-Smtp-Source: AGHT+IH31u/ZuWfmP91xHDfcAHCD0DcOOa45jDJxHQU6gjPW81C4j1piln3YOj4G6FrR78ojeMXW0g== X-Received: by 2002:a05:6602:3794:b0:7d0:5034:855a with SMTP id be20-20020a056602379400b007d05034855amr143713iob.17.1712677584799; Tue, 09 Apr 2024 08:46:24 -0700 (PDT) Received: from localhost.localdomain (97-122-82-115.hlrn.qwest.net. [97.122.82.115]) by smtp.gmail.com with ESMTPSA id x16-20020a056638161000b004828e21acffsm1734494jas.165.2024.04.09.08.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 08:46:24 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Avoid complaint warning on mingw Date: Tue, 9 Apr 2024 09:46:17 -0600 Message-ID: <20240409154617.1935108-1-tromey@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org The mingw build currently issues a warning: ./../../src/gdb/utils.h:378:56: warning: ignoring attributes on template argument 'void(const char*, va_list)' {aka 'void(const char*, char*)'} [-Wignored-attributes] This patch fixes the problem as suggested by Simon: https://sourceware.org/pipermail/gdb-patches/2024-April/207908.html ...that is, by changing the warning interceptor to a class with a single 'warn' method. --- gdb/complaints.c | 8 ++++---- gdb/complaints.h | 6 +++--- gdb/dwarf2/cooked-index.c | 2 +- gdb/utils.c | 2 +- gdb/utils.h | 28 ++++++++++++++++------------ 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/gdb/complaints.c b/gdb/complaints.c index e375c734884..d3c72df6d41 100644 --- a/gdb/complaints.c +++ b/gdb/complaints.c @@ -58,7 +58,7 @@ complaint_internal (const char *fmt, ...) warning_hook_handler handler = get_warning_hook_handler (); if (handler != nullptr) - handler (fmt, args); + handler->warn (fmt, args); else { gdb_puts (_("During symbol reading: "), gdb_stderr); @@ -85,7 +85,7 @@ thread_local complaint_interceptor *complaint_interceptor::g_complaint_intercept complaint_interceptor::complaint_interceptor () : m_saved_complaint_interceptor (&g_complaint_interceptor, this), - m_saved_warning_hook (issue_complaint) + m_saved_warning_hook (this) { } @@ -96,7 +96,7 @@ wrap_warning_hook (warning_hook_handler hook, ...) { va_list args; va_start (args, hook); - hook ("%s", args); + hook->warn ("%s", args); va_end (args); } @@ -121,7 +121,7 @@ re_emit_complaints (const complaint_collection &complaints) /* See complaints.h. */ void -complaint_interceptor::issue_complaint (const char *fmt, va_list args) +complaint_interceptor::warn (const char *fmt, va_list args) { #if CXX_STD_THREAD std::lock_guard guard (complaint_mutex); diff --git a/gdb/complaints.h b/gdb/complaints.h index 8ac4c5034ee..995c35e0ab0 100644 --- a/gdb/complaints.h +++ b/gdb/complaints.h @@ -70,7 +70,7 @@ typedef std::unordered_set complaint_collection; the main thread). Messages can be re-emitted on the main thread using re_emit_complaints, see below. */ -class complaint_interceptor +class complaint_interceptor final : public warning_hook_handler_type { public: @@ -94,8 +94,8 @@ class complaint_interceptor /* A helper function that is used by the 'complaint' implementation to issue a complaint. */ - static void issue_complaint (const char *, va_list) - ATTRIBUTE_PRINTF (1, 0); + void warn (const char *, va_list) override + ATTRIBUTE_PRINTF (2, 0); /* This object. Used by the static callback function. */ static thread_local complaint_interceptor *g_complaint_interceptor; diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 66822b575ca..cb0d1f3cd47 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -589,7 +589,7 @@ cooked_index_worker::write_to_cache (const cooked_index *idx, See PR symtab/30837. This arranges to capture all such warnings. This is safe because we know the deferred_warnings object isn't in use by any other thread at this point. */ - scoped_restore_warning_hook defer (*warn); + scoped_restore_warning_hook defer (warn); m_cache_store.store (); } } diff --git a/gdb/utils.c b/gdb/utils.c index ded03c74099..6a77f6be713 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -164,7 +164,7 @@ void vwarning (const char *string, va_list args) { if (warning_hook != nullptr) - warning_hook (string, args); + warning_hook->warn (string, args); else { std::optional term_state; diff --git a/gdb/utils.h b/gdb/utils.h index 875a2583179..65882363e3c 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -374,8 +374,19 @@ assign_return_if_changed (T &lval, const T &val) return true; } -/* A function that can be used to intercept warnings. */ -typedef gdb::function_view warning_hook_handler; +/* A class that can be used to intercept warnings. A class is used + here, rather than a gdb::function_view because it proved difficult + to use a function view in conjunction with ATTRIBUTE_PRINTF in a + way that would satisfy all compilers on all systems. And, even + though gdb only ever uses deferred_warnings here, a virtual + function is used to help Insight. */ +struct warning_hook_handler_type +{ + virtual void warn (const char *format, va_list args) ATTRIBUTE_PRINTF (2, 0) + = 0; +}; + +typedef warning_hook_handler_type *warning_hook_handler; /* Set the thread-local warning hook, and restore the old value when finished. */ @@ -418,7 +429,7 @@ extern warning_hook_handler get_warning_hook_handler (); instance of this class with the 'warn' function, and all warnings can be emitted with a single call to 'emit'. */ -struct deferred_warnings +struct deferred_warnings final : public warning_hook_handler_type { deferred_warnings () : m_can_style (gdb_stderr->can_emit_style_escape ()) @@ -444,18 +455,11 @@ struct deferred_warnings hook; see scoped_restore_warning_hook. Note that no locking is done, so users have to be careful to only install this into a single thread at a time. */ - void operator() (const char *format, va_list args) + void warn (const char *format, va_list args) override + ATTRIBUTE_PRINTF (2, 0) { string_file msg (m_can_style); - /* Clang warns if we add ATTRIBUTE_PRINTF to this method (because - the function-view wrapper doesn't also have the attribute), but - then warns again if we remove it, because this vprintf call - does not use a literal format string. So, suppress the - warnings here. */ - DIAGNOSTIC_PUSH - DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL msg.vprintf (format, args); - DIAGNOSTIC_POP m_warnings.emplace_back (std::move (msg)); }