From patchwork Fri Jun 21 22:28:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1950997 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=QzwdzmJK; 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 4W5X8W5zFLz20Wk for ; Sat, 22 Jun 2024 08:29:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2154E382FAFC for ; Fri, 21 Jun 2024 22:29:14 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id DC8D83830B73 for ; Fri, 21 Jun 2024 22:28:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC8D83830B73 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 DC8D83830B73 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719008934; cv=none; b=h75Yk+vlapZBViNnzUi3BJqzQyyJIKuUC0kQX4a/TyL7EdINal7q7pN0cPYgUXJH0SOvmFp/RDdu+km6jW96vb1OLZSD5p6RetDmV0MHh7aS+p1DBEy5P+CT90x7bQfnx3qABRP3w88kiivuKSoKdX4qpOE5UD8A7Zon2VBvtoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719008934; c=relaxed/simple; bh=l7S2qCzRms0W8D+bXK2prEpIz+qFNYX8zf5u0i0S+eM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=xcytWDlHx6nBBj8zBtOFaOQlS89d5fETnDqZRWWNFwxXZLYPPAxkOHC8/AcMSsUsXgfNBs5DpMeNLK97wCPryg8s62BXtUY7s9nPshSarffEOM2Z3G1eTflsRVcgfqFpy4ktrX6CBFzrGspR9qtT1UCXR72JgxLtuuCZqoaMSzY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719008932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0PuddT5fhSLvO3ctoX6kcaiimFlOAdwIEX6Gm5AL/qE=; b=QzwdzmJKqTtpMK5ZXf7oKu5qlLp1qDx1RwI/5rSpfNuwS6KGaQu6X8QZHHhT8pYeE92jZ4 bqPGR1xOJD0i8FhOguZ9wb5uYhz7RTY8VZlTOc/8gczKnGiWSkrTrkj5IzsB5j6gt+v4Y6 uV5WW9efmxmhhBeMTUWIKW5gGjkWXBc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-B4aS6YvHOQSjAKi6xPrNqQ-1; Fri, 21 Jun 2024 18:28:51 -0400 X-MC-Unique: B4aS6YvHOQSjAKi6xPrNqQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F57019560A2 for ; Fri, 21 Jun 2024 22:28:50 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.107]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 488393000218; Fri, 21 Jun 2024 22:28:48 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] diagnostics: remove duplicate copies of diagnostic_kind_text Date: Fri, 21 Jun 2024 18:28:47 -0400 Message-Id: <20240621222847.1167400-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.4 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, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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.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 No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Successful run of analyzer integration tests on x86_64-pc-linux-gnu. Pushed to trunk as r15-1556-gccbcde5ec0e481. gcc/ChangeLog: * diagnostic-format-json.cc (json_output_format::on_end_diagnostic): Use get_diagnostic_kind_text rather than embedding a duplicate copy of the table. * diagnostic-format-sarif.cc (make_rule_id_for_diagnostic_kind): Likewise. * diagnostic.cc (get_diagnostic_kind_text): New. * diagnostic.h (get_diagnostic_kind_text): New decl. Signed-off-by: David Malcolm --- gcc/diagnostic-format-json.cc | 8 +------- gcc/diagnostic-format-sarif.cc | 8 +------- gcc/diagnostic.cc | 8 ++++++++ gcc/diagnostic.h | 2 ++ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index ec03ac15aeb..8f2ff6cfde2 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -231,14 +231,8 @@ json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic, /* Get "kind" of diagnostic. */ { - static const char *const diagnostic_kind_text[] = { -#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T), -#include "diagnostic.def" -#undef DEFINE_DIAGNOSTIC_KIND - "must-not-happen" - }; /* Lose the trailing ": ". */ - const char *kind_text = diagnostic_kind_text[diagnostic.kind]; + const char *kind_text = get_diagnostic_kind_text (diagnostic.kind); size_t len = strlen (kind_text); gcc_assert (len > 2); gcc_assert (kind_text[len - 2] == ':'); diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 5581aa1579e..2745c72ea3e 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -662,14 +662,8 @@ maybe_get_sarif_level (diagnostic_t diag_kind) static char * make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind) { - static const char *const diagnostic_kind_text[] = { -#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T), -#include "diagnostic.def" -#undef DEFINE_DIAGNOSTIC_KIND - "must-not-happen" - }; /* Lose the trailing ": ". */ - const char *kind_text = diagnostic_kind_text[diag_kind]; + const char *kind_text = get_diagnostic_kind_text (diag_kind); size_t len = strlen (kind_text); gcc_assert (len > 2); gcc_assert (kind_text[len - 2] == ':'); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index c66aa5af5ff..8fc22466b92 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -590,6 +590,14 @@ static const char *const diagnostic_kind_text[] = { "must-not-happen" }; +/* Get unlocalized string describing KIND. */ + +const char * +get_diagnostic_kind_text (diagnostic_t kind) +{ + return diagnostic_kind_text[kind]; +} + /* Return a malloc'd string describing a location and the severity of the diagnostic, e.g. "foo.c:42:10: error: ". The caller is responsible for freeing the memory. */ diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index c6846525da3..4969f07836c 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -1121,4 +1121,6 @@ option_unspecified_p (int opt) extern char *get_cwe_url (int cwe); +extern const char *get_diagnostic_kind_text (diagnostic_t kind); + #endif /* ! GCC_DIAGNOSTIC_H */