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: 1863173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aKAC17Az; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4STVCb1klGz1yRD for ; Tue, 14 Nov 2023 00:10:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 513B0385AC26 for ; Mon, 13 Nov 2023 13:10:13 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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