From patchwork Mon Nov 13 13:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 164472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1189460vqg; Mon, 13 Nov 2023 05:10:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHd8FQe7YPUcoA/w2Qq4eeO+8OB8yClaiFYtMmj9RQEAaFs0GDjFgQsaZYdxUtybUKN0mQE X-Received: by 2002:a05:620a:4723:b0:76c:ae1f:201e with SMTP id bs35-20020a05620a472300b0076cae1f201emr14034267qkb.27.1699881036120; Mon, 13 Nov 2023 05:10:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699881036; cv=pass; d=google.com; s=arc-20160816; b=brgPBxe9Jklr9viCVEmIeLC+gwjmU+1VgHS/i/DwTT/FSV9mE4YBZMorynHmxGEaKm +eW/4hthZEhrUh/UTAcdQ7fozAJC+WZHdvWhHRebazKSX3fzwDGm2KLvm5JJie8Tfwmr LmYVLNLWjtcr5RgKq6WVGsvYwLsbtvRIzyWk4PyTk7OVuIS1zfFCIcfoWzRFCkj9PZic j6VArRlnRBjyFg4szS8WslYsk9tJ0+lKXdbCJlDF54UjweJ4NhuTjjtnZ2kQZtu/oDR+ xXtSR/GOOcppkXMM4Uz+ob981AHMfKBLgfEHzQ2J6H6avOm4cDvXAUKAiMGII6AZGEpC HdRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent:date :references:message-id:in-reply-to:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=r8KrHFvAsW67pURFL7XLnk0wNfUmEzqYUpErl96DN2M=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=G0CO15M+OcWGVvPB06PN/cNS/gljMY5P4HqcwGPYbQg66RyuYpJUHDTt8YJDykV5WS bFl55rlBKcWDq8kP2OpAbLdVKZz9pi9hjftKLC/gxi5nzNEV/zJ5uK+s7+Ew0JvNZXsA 9CTXuXK35/AY1jdh5fZWqEkXjabhmTinUsjHU7BDl1fU1dEumhsy+b3KrMpklXqgqXfY ZGPRjKZX26AuHUkmZ+cOGVu0OsvM/Y8QBbkG2rdrpMNWuE2lrt8XgbrKy8zou2Id5/qa y4KwWM4eaD/Fu0LiHJlApyYTL51a4ZYISgbkczstIHb6qjxPCwpUL9rRBVgZrvgcNt8I EFfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aKAC17Az; arc=pass (i=1); 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u17-20020ae9c011000000b0076dae328b6fsi4512180qkk.109.2023.11.13.05.10.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 05:10:36 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aKAC17Az; arc=pass (i=1); 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14FAE385735A for ; Mon, 13 Nov 2023 13:10:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9F993384F493 for ; Mon, 13 Nov 2023 13:10:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F993384F493 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9F993384F493 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699881003; cv=none; b=ar+nJnyHC7pajx7/s7cPpa2lxjC4ROnmbwqZtYgODuOYdEkcYmi2K25a+SHZtA8D+Rbplqk48wvKKbf1fuTyiLWBJauUuCJApwyIfz1RHhduqKR5Z3E0e6oeClUrQOf9UvkrYP9Vu2HbI+tX7LpMGF5+PtXU922f5FHzxT3bw7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699881003; c=relaxed/simple; bh=4DpBQKpeWeEOf/TBrXp+hBcWZTOjBiV6vynPCDgBc0s=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=OxnaNa2dZLi2s3hfCKxzYScxQB9PLF8lAbE33hpW0KFchBTBn6gd3pMX6/fstPpzzjpQwvgrUuWvh08fQyoym2EgLRQSY0cJMkVf+GyU0Wi+DIYRZnETRGTQC7U6dBwYdXXwkOJruNUgpsyrSLJOet5hrH0ux1tOnf6WHBQZuD8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699881001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r8KrHFvAsW67pURFL7XLnk0wNfUmEzqYUpErl96DN2M=; b=aKAC17AzLpAIFu+XCEx/3QrX+gSvL05UPdww1yJ/uAHVzx49YxQ4rkQDIA9rpIPNgatMhZ QfgAVOcLQtibK0CZmfD2rf2DLo3k9jVCy+mazJQRvmcm081m+bIOtH0J5opPN43k85W2Ym I2kV1kBAd10zONy0t1P2tcK6RVV9spA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-pIZii8HHMM64IeoU3kW2gA-1; Mon, 13 Nov 2023 08:09:59 -0500 X-MC-Unique: pIZii8HHMM64IeoU3kW2gA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8D0A11C05138 for ; Mon, 13 Nov 2023 13:09:59 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E9B89C0FE05 for ; Mon, 13 Nov 2023 13:09:58 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/6] c-family: Introduce pedpermerror In-Reply-To: Message-ID: References: X-From-Line: e7ee58c567233aab1b36b9d09f79af6d0108a98b Mon Sep 17 00:00:00 2001 Date: Mon, 13 Nov 2023 14:09:57 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782454457096460075 X-GMAIL-MSGID: 1782454457096460075 It turns out that permerror_opt is not directly usable for -fpermissive in the C front end. The front end uses pedwarn extensively, and pedwarns are not overridable by -Wno-* options, yet permerrors are. Add new pedpermerror helpers that turn into pedwarns if -pedantic-errors is active. Due to the dependency on flag_pedantic_errors, the new helpers are specific to the C-family front ends. For implementing the rich location variant, export emit_diagnostic_valist from gcc/diagnostic.cc in parallel to its location_t variant. gcc/ * diagnostic-core.h (emit_diagnostic_valist): Declare function. * diagnostic.cc (emit_diagnostic_valist): Define it. gcc/c-family/ * c-common.h (pedpermerror): Declare functions. * c-warn.cc (pedpermerror): Define them. --- gcc/c-family/c-common.h | 4 ++++ gcc/c-family/c-warn.cc | 34 ++++++++++++++++++++++++++++++++++ gcc/diagnostic-core.h | 3 +++ gcc/diagnostic.cc | 7 +++++++ 4 files changed, 48 insertions(+) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index b57e83d7c5d..789e0bf2459 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1486,6 +1486,10 @@ extern void warn_for_address_or_pointer_of_packed_member (tree, tree); extern void warn_parm_array_mismatch (location_t, tree, tree); extern void maybe_warn_sizeof_array_div (location_t, tree, tree, tree, tree); extern void do_warn_array_compare (location_t, tree_code, tree, tree); +extern bool pedpermerror (location_t, int, const char *, + ...) ATTRIBUTE_GCC_DIAG(3,4); +extern bool pedpermerror (rich_location *, int, const char *, + ...) ATTRIBUTE_GCC_DIAG(3,4); /* Places where an lvalue, or modifiable lvalue, may be required. Used to select diagnostic messages in lvalue_error and diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index b1bd8ba9f42..475a3e4b42e 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -3932,3 +3932,37 @@ check_for_xor_used_as_pow (location_t lhs_loc, tree lhs_val, lhs_uhwi, lhs_uhwi); } } + +/* If !flag_pedantic_errors, equivalent to permerror_opt, otherwise to + pedwarn. */ + +bool +pedpermerror (location_t location, int opt, const char *gmsgid, ...) +{ + auto_diagnostic_group d; + va_list ap; + va_start (ap, gmsgid); + rich_location richloc (line_table, location); + bool ret = emit_diagnostic_valist (flag_pedantic_errors + ? DK_PEDWARN : DK_PERMERROR, + location, opt, gmsgid, &ap); + va_end (ap); + return ret; +} + +/* Same as "pedpermerror" above, but at RICHLOC. */ + +bool +pedpermerror (rich_location *richloc, int opt, const char *gmsgid, ...) +{ + gcc_assert (richloc); + + auto_diagnostic_group d; + va_list ap; + va_start (ap, gmsgid); + bool ret = emit_diagnostic_valist (flag_pedantic_errors + ? DK_PEDWARN : DK_PERMERROR, + richloc, opt, gmsgid, &ap); + va_end (ap); + return ret; +} diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h index 04eba3d140e..eac775fb573 100644 --- a/gcc/diagnostic-core.h +++ b/gcc/diagnostic-core.h @@ -121,6 +121,9 @@ extern bool emit_diagnostic (diagnostic_t, location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(4,5); extern bool emit_diagnostic (diagnostic_t, rich_location *, int, const char *, ...) ATTRIBUTE_GCC_DIAG(4,5); +extern bool emit_diagnostic_valist (diagnostic_t, rich_location *, int, + const char *, + va_list *) ATTRIBUTE_GCC_DIAG (4,0); extern bool emit_diagnostic_valist (diagnostic_t, location_t, int, const char *, va_list *) ATTRIBUTE_GCC_DIAG (4,0); extern bool seen_error (void); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index addd6606eaa..6e73343dbdb 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -1829,6 +1829,13 @@ emit_diagnostic_valist (diagnostic_t kind, location_t location, int opt, return diagnostic_impl (&richloc, NULL, opt, gmsgid, ap, kind); } +bool +emit_diagnostic_valist (diagnostic_t kind, rich_location *richloc, int opt, + const char *gmsgid, va_list *ap) +{ + return diagnostic_impl (richloc, NULL, opt, gmsgid, ap, kind); +} + /* An informative note at LOCATION. Use this for additional details on an error message. */ void