From patchwork Fri Jun 21 22:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1950996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KR4tpsM8; 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 4W5X8B2cN3z20Wk for ; Sat, 22 Jun 2024 08:28:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2BC573830B77 for ; Fri, 21 Jun 2024 22:28:55 +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 3ED3938313A7 for ; Fri, 21 Jun 2024 22:28:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3ED3938313A7 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 3ED3938313A7 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=1719008917; cv=none; b=UWPNhrYmuxvOHzdAglJDHDHZU88oIkZcgNP22+4wS6J1lmFhliKiOYGIyBcUQ1d7JN49NsRGA9onMcVHtyl9o397TLdmB8SY7RSvZMFo7G9U8aPVfsJe0akl+tz/UYZIco4HS42mMNP9sIjFr7/0laVjxE1YuQBNATdqDAi4SX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719008917; c=relaxed/simple; bh=mfFQROclT9NlMfM93vqaSIBCM1jJ67SSfu2hfBcUuM8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=pgU0TGn1AOEru0cEmNbb7pWL90LojjxF8WJAXaoMW1YEgcuzDZW5ocb5svxhmAFTcU7id1AP2JkbPe5r3y5GtRx53z4Cngyx1F/IGVBjjhkE9QJoqX9Yk/yLzyvTKERaeNIj++xbmuyViHfK+EAA6pbEYjES8VXajUZrl1m45yE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719008914; 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=A1ArAdRuxiszRZx0hb6DRcTV1iDIkBvgzwcsIKsLvS4=; b=KR4tpsM8SHwntDx80Nej59iEa0iBKI6iUl6CrBtmqGy4iC9qT48t9Dw1blGr8LImLcQ1Fc pseIzaabvbwkZwDy3GB8OlC+45tGlE6ZI/MXPd15Uq0cApVNPoFXEfMJmx3FXhjj3lfFi/ kFpSmZvZkcPwtyJAqXqgORjf/S97Kh0= 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-465-72Pu5sDZPxOfveMUPGlETA-1; Fri, 21 Jun 2024 18:28:32 -0400 X-MC-Unique: 72Pu5sDZPxOfveMUPGlETA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 3FE6C19560AB for ; Fri, 21 Jun 2024 22:28:31 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.107]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6AA391956048; Fri, 21 Jun 2024 22:28:30 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] diagnostics: move diagnostic_{event, path} functions to diagnostic-path.cc Date: Fri, 21 Jun 2024 18:28:28 -0400 Message-Id: <20240621222828.1167350-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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-1555-g4819dc7d4b84af. gcc/ChangeLog: * diagnostic-path.cc (diagnostic_event::meaning::dump_to_pp): Move here from diagnostic.cc. (diagnostic_event::meaning::maybe_get_verb_str): Likewise. (diagnostic_event::meaning::maybe_get_noun_str): Likewise. (diagnostic_event::meaning::maybe_get_property_str): Likewise. (diagnostic_path::get_first_event_in_a_function): Likewise. (diagnostic_path::interprocedural_p): Likewise. (debug): Likewise for diagnostic_path * overload. * diagnostic.cc (diagnostic_event::meaning::dump_to_pp): Move from here to diagnostic-path.cc. (diagnostic_event::meaning::maybe_get_verb_str): Likewise. (diagnostic_event::meaning::maybe_get_noun_str): Likewise. (diagnostic_event::meaning::maybe_get_property_str): Likewise. (diagnostic_path::get_first_event_in_a_function): Likewise. (diagnostic_path::interprocedural_p): Likewise. (debug): Likewise for diagnostic_path * overload. Signed-off-by: David Malcolm --- gcc/diagnostic-path.cc | 168 +++++++++++++++++++++++++++++++++++++++++ gcc/diagnostic.cc | 168 ----------------------------------------- 2 files changed, 168 insertions(+), 168 deletions(-) diff --git a/gcc/diagnostic-path.cc b/gcc/diagnostic-path.cc index 882dc1c5805..ea5b1f65e02 100644 --- a/gcc/diagnostic-path.cc +++ b/gcc/diagnostic-path.cc @@ -45,6 +45,174 @@ along with GCC; see the file COPYING3. If not see # pragma GCC diagnostic ignored "-Wformat-diag" #endif +/* class diagnostic_event. */ + +/* struct diagnostic_event::meaning. */ + +void +diagnostic_event::meaning::dump_to_pp (pretty_printer *pp) const +{ + bool need_comma = false; + pp_character (pp, '{'); + if (const char *verb_str = maybe_get_verb_str (m_verb)) + { + pp_printf (pp, "verb: %qs", verb_str); + need_comma = true; + } + if (const char *noun_str = maybe_get_noun_str (m_noun)) + { + if (need_comma) + pp_string (pp, ", "); + pp_printf (pp, "noun: %qs", noun_str); + need_comma = true; + } + if (const char *property_str = maybe_get_property_str (m_property)) + { + if (need_comma) + pp_string (pp, ", "); + pp_printf (pp, "property: %qs", property_str); + need_comma = true; + } + pp_character (pp, '}'); +} + +/* Get a string (or NULL) for V suitable for use within a SARIF + threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8). */ + +const char * +diagnostic_event::meaning::maybe_get_verb_str (enum verb v) +{ + switch (v) + { + default: + gcc_unreachable (); + case VERB_unknown: + return NULL; + case VERB_acquire: + return "acquire"; + case VERB_release: + return "release"; + case VERB_enter: + return "enter"; + case VERB_exit: + return "exit"; + case VERB_call: + return "call"; + case VERB_return: + return "return"; + case VERB_branch: + return "branch"; + case VERB_danger: + return "danger"; + } +} + +/* Get a string (or NULL) for N suitable for use within a SARIF + threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8). */ + +const char * +diagnostic_event::meaning::maybe_get_noun_str (enum noun n) +{ + switch (n) + { + default: + gcc_unreachable (); + case NOUN_unknown: + return NULL; + case NOUN_taint: + return "taint"; + case NOUN_sensitive: + return "sensitive"; + case NOUN_function: + return "function"; + case NOUN_lock: + return "lock"; + case NOUN_memory: + return "memory"; + case NOUN_resource: + return "resource"; + } +} + +/* Get a string (or NULL) for P suitable for use within a SARIF + threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8). */ + +const char * +diagnostic_event::meaning::maybe_get_property_str (enum property p) +{ + switch (p) + { + default: + gcc_unreachable (); + case PROPERTY_unknown: + return NULL; + case PROPERTY_true: + return "true"; + case PROPERTY_false: + return "false"; + } +} + +/* class diagnostic_path. */ + +/* Subroutine of diagnostic_path::interprocedural_p. + Look for the first event in this path that is within a function + i.e. has a non-null logical location for which function_p is true. + If found, write its index to *OUT_IDX and return true. + Otherwise return false. */ + +bool +diagnostic_path::get_first_event_in_a_function (unsigned *out_idx) const +{ + const unsigned num = num_events (); + for (unsigned i = 0; i < num; i++) + { + const diagnostic_event &event = get_event (i); + if (const logical_location *logical_loc = event.get_logical_location ()) + if (logical_loc->function_p ()) + { + *out_idx = i; + return true; + } + } + return false; +} + +/* Return true if the events in this path involve more than one + function, or false if it is purely intraprocedural. */ + +bool +diagnostic_path::interprocedural_p () const +{ + /* Ignore leading events that are outside of any function. */ + unsigned first_fn_event_idx; + if (!get_first_event_in_a_function (&first_fn_event_idx)) + return false; + + const diagnostic_event &first_fn_event = get_event (first_fn_event_idx); + int first_fn_stack_depth = first_fn_event.get_stack_depth (); + + const unsigned num = num_events (); + for (unsigned i = first_fn_event_idx + 1; i < num; i++) + { + if (!same_function_p (first_fn_event_idx, i)) + return true; + if (get_event (i).get_stack_depth () != first_fn_stack_depth) + return true; + } + return false; +} + +/* Print PATH by emitting a dummy "note" associated with it. */ + +DEBUG_FUNCTION +void debug (diagnostic_path *path) +{ + rich_location richloc (line_table, UNKNOWN_LOCATION); + richloc.set_path (path); + inform (&richloc, "debug path"); +} + /* Anonymous namespace for path-printing code. */ namespace { diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 471135f16de..c66aa5af5ff 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -918,164 +918,6 @@ diagnostic_context::show_any_path (const diagnostic_info &diagnostic) print_path (path); } -/* class diagnostic_event. */ - -/* struct diagnostic_event::meaning. */ - -void -diagnostic_event::meaning::dump_to_pp (pretty_printer *pp) const -{ - bool need_comma = false; - pp_character (pp, '{'); - if (const char *verb_str = maybe_get_verb_str (m_verb)) - { - pp_printf (pp, "verb: %qs", verb_str); - need_comma = true; - } - if (const char *noun_str = maybe_get_noun_str (m_noun)) - { - if (need_comma) - pp_string (pp, ", "); - pp_printf (pp, "noun: %qs", noun_str); - need_comma = true; - } - if (const char *property_str = maybe_get_property_str (m_property)) - { - if (need_comma) - pp_string (pp, ", "); - pp_printf (pp, "property: %qs", property_str); - need_comma = true; - } - pp_character (pp, '}'); -} - -/* Get a string (or NULL) for V suitable for use within a SARIF - threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8). */ - -const char * -diagnostic_event::meaning::maybe_get_verb_str (enum verb v) -{ - switch (v) - { - default: - gcc_unreachable (); - case VERB_unknown: - return NULL; - case VERB_acquire: - return "acquire"; - case VERB_release: - return "release"; - case VERB_enter: - return "enter"; - case VERB_exit: - return "exit"; - case VERB_call: - return "call"; - case VERB_return: - return "return"; - case VERB_branch: - return "branch"; - case VERB_danger: - return "danger"; - } -} - -/* Get a string (or NULL) for N suitable for use within a SARIF - threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8). */ - -const char * -diagnostic_event::meaning::maybe_get_noun_str (enum noun n) -{ - switch (n) - { - default: - gcc_unreachable (); - case NOUN_unknown: - return NULL; - case NOUN_taint: - return "taint"; - case NOUN_sensitive: - return "sensitive"; - case NOUN_function: - return "function"; - case NOUN_lock: - return "lock"; - case NOUN_memory: - return "memory"; - case NOUN_resource: - return "resource"; - } -} - -/* Get a string (or NULL) for P suitable for use within a SARIF - threadFlowLocation "kinds" property (SARIF v2.1.0 section 3.38.8). */ - -const char * -diagnostic_event::meaning::maybe_get_property_str (enum property p) -{ - switch (p) - { - default: - gcc_unreachable (); - case PROPERTY_unknown: - return NULL; - case PROPERTY_true: - return "true"; - case PROPERTY_false: - return "false"; - } -} - -/* class diagnostic_path. */ - -/* Subroutine of diagnostic_path::interprocedural_p. - Look for the first event in this path that is within a function - i.e. has a non-null logical location for which function_p is true. - If found, write its index to *OUT_IDX and return true. - Otherwise return false. */ - -bool -diagnostic_path::get_first_event_in_a_function (unsigned *out_idx) const -{ - const unsigned num = num_events (); - for (unsigned i = 0; i < num; i++) - { - const diagnostic_event &event = get_event (i); - if (const logical_location *logical_loc = event.get_logical_location ()) - if (logical_loc->function_p ()) - { - *out_idx = i; - return true; - } - } - return false; -} - -/* Return true if the events in this path involve more than one - function, or false if it is purely intraprocedural. */ - -bool -diagnostic_path::interprocedural_p () const -{ - /* Ignore leading events that are outside of any function. */ - unsigned first_fn_event_idx; - if (!get_first_event_in_a_function (&first_fn_event_idx)) - return false; - - const diagnostic_event &first_fn_event = get_event (first_fn_event_idx); - int first_fn_stack_depth = first_fn_event.get_stack_depth (); - - const unsigned num = num_events (); - for (unsigned i = first_fn_event_idx + 1; i < num; i++) - { - if (!same_function_p (first_fn_event_idx, i)) - return true; - if (get_event (i).get_stack_depth () != first_fn_stack_depth) - return true; - } - return false; -} - /* class logical_location. */ /* Return true iff this is a function or method. */ @@ -2543,16 +2385,6 @@ set_text_art_charset (enum diagnostic_text_art_charset charset) } } -/* Print PATH by emitting a dummy "note" associated with it. */ - -DEBUG_FUNCTION -void debug (diagnostic_path *path) -{ - rich_location richloc (line_table, UNKNOWN_LOCATION); - richloc.set_path (path); - inform (&richloc, "debug path"); -} - /* Really call the system 'abort'. This has to go right at the end of this file, so that there are no functions after it that call abort and get the system abort instead of our macro. */