From patchwork Wed Nov 20 21:13:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514233-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="g3qhhX3w"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="bLHkbgJe"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFdF2lSTz9s7T for ; Thu, 21 Nov 2019 08:07:29 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=Q9o Bu1ROD7DiMHOSLROXMYTFVxcwD0V9In+hsp2F/X84YZvp4KlMNRDc4JfkW4jdXTj paiCzxyIctU72XYVjiippXwQdzTZxKWw63BQm3ZUNU2AXYPPgidSBYlNU36vRM1t cpZojTwrovBcIVRKA1GBE56p3HjiWJdnN0zXmGng= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=quBS6GwZf 8HnSHk6VORFLxcQWEM=; b=g3qhhX3wTCb4+JwkzdfycVg6/kK1NZW5gtZ2SIC2i Y0rY8dor81Tb+uoGALpiVxARjlTIltWE0GpzEIStGFYGWV/Adt/n42rxNSCcYJtd 0pa+JUr2khlnpd9P+dVZDnEFfw3U+iQ+RY74H/sN49MzzryddKLrYAWuwvNUGriy Co= Received: (qmail 85291 invoked by alias); 20 Nov 2019 21:07:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85226 invoked by uid 89); 20 Nov 2019 21:07:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=1087 X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1HURYIg51R1Gx0KU58SG3pH4tgsb0QSbQJp6SYdjVEk=; b=bLHkbgJemSvB5WrGyre2UGGXbTv+FbtGfak27pOYuSMTNgUGhdLs3gL/esVrWnsoDsWhrp OsZFcljeOf/cEnH9SOebZ1OFNWuFDlG+bV3nUPRN4AX0r0aKLOrDiklUxQtywq0FuTTLWo WdVn7bo3rA2L4Zp1QzlJycUcjevqxJY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-303-mO3EdpgZN4aF2R3R5c2djw-1; Wed, 20 Nov 2019 16:07:06 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C645801FCF for ; Wed, 20 Nov 2019 21:07:05 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DE93106427B; Wed, 20 Nov 2019 21:07:03 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 01/11] [analyzer] Fix up for params refactoring Date: Wed, 20 Nov 2019 16:13:40 -0500 Message-Id: <1574284430-8776-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes gcc/ChangeLog: * analyzer/analysis-plan.cc: Remove include of "params.h". (analysis_plan::use_summary_p): Update for conversion of params to options. * analyzer/engine.cc: Remove include of "params.h". (exploded_graph::get_or_create_node): Update for conversion of params to options. (exploded_graph::process_worklist): Likewise. * analyzer/program-point.cc: Remove include of "params.h". (program_point::on_edge): Update for conversion of params to options. --- gcc/analyzer/analysis-plan.cc | 3 +-- gcc/analyzer/engine.cc | 6 ++---- gcc/analyzer/program-point.cc | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/gcc/analyzer/analysis-plan.cc b/gcc/analyzer/analysis-plan.cc index 920783b..38123ff 100644 --- a/gcc/analyzer/analysis-plan.cc +++ b/gcc/analyzer/analysis-plan.cc @@ -26,7 +26,6 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "timevar.h" #include "ipa-utils.h" -#include "params.h" #include "analyzer/analyzer.h" #include "analyzer/analysis-plan.h" #include "analyzer/supergraph.h" @@ -108,7 +107,7 @@ analysis_plan::use_summary_p (const cgraph_edge *edge) const /* Require the callee to be sufficiently complex to be worth summarizing. */ if ((int)m_sg.get_num_snodes (callee->get_fun ()) - < PARAM_VALUE (PARAM_ANALYZER_MIN_SNODES_FOR_CALL_SUMMARY)) + < param_analyzer_min_snodes_for_call_summary) return false; return true; diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 34941d2..c4ca5bf 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -23,7 +23,6 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "tree.h" -#include "params.h" #include "gcc-rich-location.h" #include "analyzer/exploded-graph.h" #include "analyzer/analysis-plan.h" @@ -1719,7 +1718,7 @@ exploded_graph::get_or_create_node (const program_point &point, /* Impose a limit on the number of enodes per program point, and simply stop if we exceed it. */ if ((int)per_point_data->m_enodes.length () - > PARAM_VALUE (PARAM_ANALYZER_MAX_ENODES_PER_PROGRAM_POINT)) + > param_analyzer_max_enodes_per_program_point) { log ("not creating enode; too many at program point"); warning_at (point.get_location (), OPT_Wanalyzer_too_complex, @@ -2044,8 +2043,7 @@ exploded_graph::process_worklist () entry ENs, one per phi; the number of PK_AFTER_SUPERNODE ought to be equivalent to the number of supernodes multiplied by the number of states. */ - const int limit - = m_sg.num_nodes () * PARAM_VALUE (PARAM_ANALYZER_BB_EXPLOSION_FACTOR); + const int limit = m_sg.num_nodes () * param_analyzer_bb_explosion_factor; if (m_global_stats.m_num_nodes[PK_AFTER_SUPERNODE] > limit) { log ("bailing out; too many nodes"); diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc index fcf77af..ea84238 100644 --- a/gcc/analyzer/program-point.cc +++ b/gcc/analyzer/program-point.cc @@ -25,7 +25,6 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "gimple-pretty-print.h" #include "gcc-rich-location.h" -#include "params.h" #include "analyzer/program-point.h" #include "analyzer/exploded-graph.h" #include "analyzer/analysis-plan.h" @@ -262,7 +261,7 @@ program_point::on_edge (exploded_graph &eg, applies to recursion (and mutual recursion), not to general call stacks. */ if (m_call_string.calc_recursion_depth () - > PARAM_VALUE (PARAM_ANALYZER_MAX_RECURSION_DEPTH)) + > param_analyzer_max_recursion_depth) { eg.log ("rejecting call edge: recursion limit exceeded"); // TODO: issue a sorry for this? From patchwork Wed Nov 20 21:13:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514234-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="utmcQUdh"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="f5c+Ja2a"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFdT6TS9z9sPT for ; Thu, 21 Nov 2019 08:07:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=is2 Q8jCutB/vatGFpy7IPrmE0UL9PSDFam0NvoGBOhupqpRGjkgA/D7FHHk+9oVUSOU CPU55FRuNGX4uIX+/xr7hC8HX8Ik5NsxXt+pdQmPTnw0aLxO8sJb13iSsZBA0D5x Sj9RT58SrXkM53VvoU6FP5eMFBvDPcoKAZIf+Ta8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=kRbQvLKRw 58+N1w3dV7qEVZ3Cio=; b=utmcQUdhRLzQ8+kk911lfC8FdiHkoAbV9u0sW3WBm 3wn9t9yp0qKWExRkheM+gaY+DYMXF8c66CNByrmH7QsoXjdW4gUfG7SlSNe0E1yd 4TjpFDanhJw1YPo2QhAI2wSOuo4NtNoAA1TsarynxX0/Da645AissO+l3bQedu3N c8= Received: (qmail 85662 invoked by alias); 20 Nov 2019 21:07:13 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85621 invoked by uid 89); 20 Nov 2019 21:07:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RTU4TLGTNtE0z8cRuS5RpmwWlB8bx3XRuBvfq5sWCXU=; b=f5c+Ja2aiF22DQgWQ+VdLDfj9G1IqsCdQv5fV3Nf4oLxkyjt5VkcRdPL8Eo8lzHWsFlcVd M3kQpMD488Ae5p+y3rNYKx2YyCOlC76bB3ynTdJiaZAvj9nmyIOJ+vUJO22YPyR7Nergv4 FERx0TkUICY1mJ0USTCR4doDWWwxVz8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-YDupjwH4OPGnKqJD4LSM4w-1; Wed, 20 Nov 2019 16:07:08 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E4A4801E74 for ; Wed, 20 Nov 2019 21:07:07 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81C20106427B; Wed, 20 Nov 2019 21:07:05 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 02/11] [analyzer] Fixup metadata-handling for "json::number" to "json::integer_number" Date: Wed, 20 Nov 2019 16:13:41 -0500 Message-Id: <1574284430-8776-3-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes r277284 eliminated json::number in favor of json::float_number and json::integer_number. Update the diagnostic metadata code accordingly. gcc/ChangeLog: * diagnostic-format-json.cc (json_from_metadata): Use json::integer_number. --- gcc/diagnostic-format-json.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index 24a08c0..f73d09b 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -112,7 +112,8 @@ json_from_metadata (const diagnostic_metadata *metadata) json::object *metadata_obj = new json::object (); if (metadata->get_cwe ()) - metadata_obj->set ("cwe", new json::number (metadata->get_cwe ())); + metadata_obj->set ("cwe", + new json::integer_number (metadata->get_cwe ())); return metadata_obj; } From patchwork Wed Nov 20 21:13:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514235-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OAjZ7kzy"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Qr1I4P6Q"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFdh5YBMz9s7T for ; Thu, 21 Nov 2019 08:07:52 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=Y4/ u+4/j/my3mxYnnc7IrvZ73uwwoRQ6gaM2GRD7CNDLKPjh/Vid+vPhRkzRYIauD+N NawXc4+DSLkWIxPlcTAUK1lEVLeJ6Ii2YUiVL7rSexd+nJ70Lm/zJpEOym7dkSW5 vCjlcHQ1tVeV3cJhMojejlY7ILeyXy2g5q8C8x2U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=YtU6NbYHo ZZUZGuP08tzNdh8DAI=; b=OAjZ7kzyKrkOsnsxI8d2bMWuIbAjJP51uGQF7Z4Yi oMVmkR/tqDkJb10+6ZfaJ9ve3qisZsfp27VBgnEaZ5lYtUJdAvsPsdhdqPdvcrbM UwvLaOarFIh9kYHwarwZsBD0HQrNoosCBQbuzapwRbCc7SGBQk/U6J3b4hh4/95A Jw= Received: (qmail 85869 invoked by alias); 20 Nov 2019 21:07:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85813 invoked by uid 89); 20 Nov 2019 21:07:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jkf/HhSC2GG2XMtNeQa8MDUgVrnDS7xtMaZZGnRwxHc=; b=Qr1I4P6QOa2MbFoL8zBHPxt7qr+Im7k+oXzg3dROGzPyaybXa0hd/zgt2JX7lG2MiMlyF0 ghooellQ2PbOy6x0Wpe3jy+GPXO4olR6MYa/TcEMfhsuae2HT6gTZ/DMz004/ehY9HC/bT FjiXhW8g8YfcRix0qpojuw2hc8Azeig= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-I8AI19jeMKyS1Yit8FADCQ-1; Wed, 20 Nov 2019 16:07:09 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01DA9800A02 for ; Wed, 20 Nov 2019 21:07:09 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BC20106427B; Wed, 20 Nov 2019 21:07:07 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 03/11] [analyzer] Fixup diagnostic_path for "json::number" to "json::integer_number" Date: Wed, 20 Nov 2019 16:13:42 -0500 Message-Id: <1574284430-8776-4-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes r277284 eliminated json::number in favor of json::float_number and json::integer_number. Update the diagnostic_path code accordingly. gcc/ChangeLog: * tree-diagnostic-path.cc (default_tree_make_json_for_path): Fix overlong line. Use json::integer_number. --- gcc/tree-diagnostic-path.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc index d044152..abb418d 100644 --- a/gcc/tree-diagnostic-path.cc +++ b/gcc/tree-diagnostic-path.cc @@ -484,7 +484,8 @@ default_tree_diagnostic_path_printer (diagnostic_context *context, doesn't have access to trees (for m_fndecl). */ json::value * -default_tree_make_json_for_path (diagnostic_context *, const diagnostic_path *path) +default_tree_make_json_for_path (diagnostic_context *, + const diagnostic_path *path) { json::array *path_array = new json::array (); for (unsigned i = 0; i < path->num_events (); i++) @@ -504,7 +505,8 @@ default_tree_make_json_for_path (diagnostic_context *, const diagnostic_path *pa = identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)); event_obj->set ("function", new json::string (function)); } - event_obj->set ("depth", new json::number (event.get_stack_depth ())); + event_obj->set ("depth", + new json::integer_number (event.get_stack_depth ())); path_array->append (event_obj); } return path_array; From patchwork Wed Nov 20 21:13:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514236-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="niP39nYR"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="B9TVQZu4"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFdw1wQPz9sPL for ; Thu, 21 Nov 2019 08:08:04 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=yxz nu4FF+LeFbqlgEd0NB5E6FjFkqncveRfgM3a7GRnocI4jZhoX7nLzMBa+bfz/IlL BOAUXjnuEKXAS8MnU2RoraVTwnJN6p8Ieb7iZDkSqQnkdnAlO6EskPldURK56w41 Kw2ESCnv/1dIMiSgW4Zxp6mviMMkWfCNwfAmwYfU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=CVl24HcXr bhzPYrQIqEwZj0Q7PI=; b=niP39nYR+VIUb9nTBSROq0h9xX/2ObrjsIxYVoKG8 6KcpWK9DoPFzgxzIQ41bbQqigpxape54pC5Tmrcbfe+UIMDiNgBzflK0iWbQTdCD k/EPhS3JfK2rAcp/kgfarZzGh3sGbfYxzcuDNfH+ZyuUCNX8fmhOl85PyB32HCMn EQ= Received: (qmail 86071 invoked by alias); 20 Nov 2019 21:07:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86026 invoked by uid 89); 20 Nov 2019 21:07:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=tha, exploded X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mfx5XV/009EyJ5/SH42DB8LQaAzc1sDnpXa0/kC1cWM=; b=B9TVQZu4SOZkUrnSR2c5Ow43IELUeCF73DU7VxkQWyWXIROxi7+blVpfFH0S61FA60Pmw/ +B0QericERu8eakjWVrddyPJ8E1sK/KuNpJ6uqRg4jC8+7bCfXdnhOKLDcwaqOO4VjIxGO VMZeQCP57NHLseNjdjXmEXCb6ztGzC0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-HeLrZKhvM5SK6WvZ2eR6qg-1; Wed, 20 Nov 2019 16:07:11 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CD49107ACC4 for ; Wed, 20 Nov 2019 21:07:10 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CBAE106427B; Wed, 20 Nov 2019 21:07:09 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 04/11] [analyzer] Add params to plugin.opt Date: Wed, 20 Nov 2019 16:13:43 -0500 Message-Id: <1574284430-8776-5-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes Various commits on 2019-11-12 including r278083 through r278087 reimplemented parameter-handling in terms of options, so that params are defined in params.opt rather than params.def. This patch adds the params for the analyzer to plugin.opt, replacing the patch: [PATCH 22/49] analyzer: params.def: new parameters https://gcc.gnu.org/ml/gcc-patches/2019-11/msg01520.html from the original version of the patch kit. gcc/ChangeLog: * analyzer/plugin.opt (-param=analyzer-bb-explosion-factor=): New param. (-param=analyzer-max-enodes-per-program-point=): New param. (-param=analyzer-max-recursion-depth=): New param. (-param=analyzer-min-snodes-for-call-summary=): New param. --- gcc/analyzer/plugin.opt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gcc/analyzer/plugin.opt b/gcc/analyzer/plugin.opt index 55f54bb..8408f1c 100644 --- a/gcc/analyzer/plugin.opt +++ b/gcc/analyzer/plugin.opt @@ -22,6 +22,22 @@ ; Please try to keep this file in ASCII collating order. +-param=analyzer-bb-explosion-factor= +Common Joined UInteger Var(param_analyzer_bb_explosion_factor) Init(5) Param +The maximum number of 'after supernode' exploded nodes within the analyzer per supernode, before terminating analysis. + +-param=analyzer-max-enodes-per-program-point= +Common Joined UInteger Var(param_analyzer_max_enodes_per_program_point) Init(8) Param +The maximum number of exploded nodes per program point within the analyzer, before terminating analysis of that point. + +-param=analyzer-max-recursion-depth= +Common Joined UInteger Var(param_analyzer_max_recursion_depth) Init(2) Param +The maximum number of times a callsite can appear in a call stack within the analyzer, before terminating analysis of a call tha would recurse deeper. + +-param=analyzer-min-snodes-for-call-summary= +Common Joined UInteger Var(param_analyzer_min_snodes_for_call_summary) Init(10) Param +The minimum number of supernodes within a function for the analyzer to consider summarizing its effects at call sites. + Wanalyzer-double-fclose Common Var(warn_analyzer_double_fclose) Init(1) Warning Warn about code paths in which a stdio FILE can be closed more than once. From patchwork Wed Nov 20 21:13:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514237-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mmcqfM8a"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="b6Ux5xe+"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFf753Qlz9s7T for ; Thu, 21 Nov 2019 08:08:15 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=qzU jjJnKFPP/mJqoTapkXl6Cz+1bEZ0QcBVGyhrCbjqVGUOoXwG4LfBEOar45ghB7Ow StTnGs76VNJUWqcV4EQwoMvRh6ykgdL5Dc4CfVZsD0V/sujUeooZn45jMNaHS7j6 Ty+YKqi5J98FC7yzDJnAVTxnL6aXsPmRMD8orUeA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=jPCmr+rmf 4w9HvvAaO3l8KcKArY=; b=mmcqfM8a4Z3x1faTABXz7soK9cO/ONAiOVL74DeRU 4+xoUYFYACYj+Dg+wnL3vCBFjPwXbgAesvVSFLgvYtWZhA8tjSu/NkfOn/IEQWW6 MB4C/ctgk6DDOKeKu3y/I7m/B9rih0jeBAC34T3jAnxzv2rIJuhRoOsXegbOUIDs pg= Received: (qmail 86291 invoked by alias); 20 Nov 2019 21:07:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86227 invoked by uid 89); 20 Nov 2019 21:07:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kW7XaFwT+80pIm9qJrGkfvsYLd0jgtR8Js5xp7tM8Q0=; b=b6Ux5xe+OmQyg1/6c7BonJYhCGfV9N9TSlUcmzB+ANskUC7XpZKLtuh5+5HdWlrBgqybAT aZtsgtRyQNs1oQf0EJwcPFus9znI3BRDFVDYL6Mt7q1SBTh6cGTvcj136n/gFUKEuftH9n bIaZ6wWWivA5ctz1JrklGEZeq/XDkxU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-j1MsN9QsP-SzHZdB64Zp2g-1; Wed, 20 Nov 2019 16:07:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 998A1107ACC5 for ; Wed, 20 Nov 2019 21:07:11 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADA90106427B; Wed, 20 Nov 2019 21:07:10 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 05/11] [analyzer] Avoid using "convert" Date: Wed, 20 Nov 2019 16:13:44 -0500 Message-Id: <1574284430-8776-6-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes "convert" is not implemented in lto1, leading to an ICE when used. This patch implements a build_cast function for the analyzer and uses it to replace the call to "convert" when handling casts in region_model. This fixes numerous ICEs when running the analyzer from LTO. gcc/ChangeLog: * analyzer/region-model.cc: Include "convert.h" and "target.h". (build_cast): New function, adapted from jit-playback.c. (region_model::maybe_cast_1): Use it to replace the call to "convert". * doc/analyzer.texi (Limitations): Remove the reference to convert and ICEs for casts in LTO. --- gcc/analyzer/region-model.cc | 55 +++++++++++++++++++++++++++++++++++++++++++- gcc/doc/analyzer.texi | 7 +++--- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index f28661f..197f1be 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -29,6 +29,8 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "tree-dfa.h" #include "stringpool.h" +#include "convert.h" +#include "target.h" #include "selftest.h" #include "diagnostic-color.h" #include "diagnostic-metadata.h" @@ -4694,6 +4696,56 @@ region_model::get_region_for_label (tree label) return func_reg->get_or_create (this, func_rid, label, TREE_TYPE (label)); } +/* Build a cast of SRC_EXPR to DST_TYPE, or return NULL_TREE. + + Adapted from gcc::jit::playback::context::build_cast, which in turn is + adapted from + - c/c-typeck.c:build_c_cast + - c/c-convert.c: convert + - convert.h + Only some kinds of cast are currently supported here. */ + +static tree +build_cast (tree dst_type, tree src_expr) +{ + tree result = targetm.convert_to_type (dst_type, src_expr); + if (result) + return result; + enum tree_code dst_code = TREE_CODE (dst_type); + switch (dst_code) + { + case INTEGER_TYPE: + case ENUMERAL_TYPE: + result = convert_to_integer (dst_type, src_expr); + goto maybe_fold; + + case BOOLEAN_TYPE: + /* Compare with c_objc_common_truthvalue_conversion and + c_common_truthvalue_conversion. */ + /* For now, convert to: (src_expr != 0) */ + result = build2 (NE_EXPR, dst_type, + src_expr, + build_int_cst (TREE_TYPE (src_expr), 0)); + goto maybe_fold; + + case REAL_TYPE: + result = convert_to_real (dst_type, src_expr); + goto maybe_fold; + + case POINTER_TYPE: + result = build1 (NOP_EXPR, dst_type, src_expr); + goto maybe_fold; + + default: + return NULL_TREE; + + maybe_fold: + if (TREE_CODE (result) != C_MAYBE_CONST_EXPR) + result = fold (result); + return result; + } +} + /* If the type of SID's underlying value is DST_TYPE, return SID. Otherwise, attempt to create (or reuse) an svalue representing an access of SID as a DST_TYPE and return that value's svalue_id. */ @@ -4740,7 +4792,8 @@ region_model::maybe_cast_1 (tree dst_type, svalue_id sid) /* Attempt to cast constants. */ if (tree src_cst = sval->maybe_get_constant ()) { - tree dst = convert (dst_type, src_cst); + tree dst = build_cast (dst_type, src_cst); + gcc_assert (dst != NULL_TREE); if (CONSTANT_CLASS_P (dst)) return get_or_create_constant_svalue (dst); } diff --git a/gcc/doc/analyzer.texi b/gcc/doc/analyzer.texi index 8e7b26f..adf375a 100644 --- a/gcc/doc/analyzer.texi +++ b/gcc/doc/analyzer.texi @@ -382,11 +382,10 @@ The checkers are currently hardcoded and don't allow for user extensibility (e.g. adding allocate/release pairs). @item Although the analyzer's test suite has a proof-of-concept test case for -LTO, it will crash on anything non-trivial. There are various +LTO, LTO support hasn't had extensive testing. There are various lang-specific things in the analyzer that assume C rather than LTO. -For example, casts are currently implemented via @code{convert}, and this -leads to an ICE on LTO. Similarly, SSA names are printed to the user in -``raw'' form, rather than printing the underlying variable name. +For example, SSA names are printed to the user in ``raw'' form, rather +than printing the underlying variable name. @end itemize Some ideas for other checkers From patchwork Wed Nov 20 21:13:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514238-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FawT/vxB"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="KGua9go1"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFfM3RgZz9s7T for ; Thu, 21 Nov 2019 08:08:27 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=yxB R7DjpJv31+XD3QO9IKxLUSr4MdX7VOTuk001um6jyRfEzvpFwdkpTwo89pUZyXF/ x8RVrq0BBL5Jq2IBVdHtDwHhXNnXc/ahT7J8QsgEkRhpzgGucwNEG9eiLxRSdeQw YxVtieCBLuMckfS87Wnqijg8xsyLhBuksumEKE9s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=v4Ckv6x/A Mh7cc8mjcYWsRKtJIg=; b=FawT/vxBJTGXlmj3TdIbM1dCyw04KlWhQP8qsS433 ZBBV9H9z5tXnEkcTM2s/V9bjOy9bejqQPQIe2nsDa9IIfi621m6Mtm84lezn/BlY l2a4F3m+TPkDPXARei1i+mn8HY10If9J83B9uoXSSGRcQ23Ab5G38ZWFkDba1ebk 5c= Received: (qmail 86444 invoked by alias); 20 Nov 2019 21:07:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86359 invoked by uid 89); 20 Nov 2019 21:07:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z4Xk+Km/tyCd+VKyTDdISr8gYPRJgQ5yTK/57ma3s5Y=; b=KGua9go108OPd37wounz2BczdpFIBGz4DUsqSMNzObXK8RnZfsiYLGTEIGwhKLPFmG9cOg H9OQ/JvU3puWcKSJQeMDHmMs98sG0EUHLBrF/XhBZdkifLHJZX2aCtkqVUVhARJ7w2dgSS viNpWJESsl3bOrF8YqJREMO8p6BeEws= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-322-5FLoJIsJMUCo0TGZuEHdqQ-1; Wed, 20 Nov 2019 16:07:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8F6D107ACC4 for ; Wed, 20 Nov 2019 21:07:12 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09883106427B; Wed, 20 Nov 2019 21:07:11 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 06/11] [analyzer] More LTO test coverage Date: Wed, 20 Nov 2019 16:13:45 -0500 Message-Id: <1574284430-8776-7-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes gcc/testsuite/ChangeLog: * gcc.dg/analyzer/malloc-ipa-8-lto-a.c: New test. * gcc.dg/analyzer/malloc-ipa-8-lto-b.c: New test. * gcc.dg/analyzer/malloc-ipa-8-lto-c.c: New test. * gcc.dg/analyzer/malloc-ipa-8-lto.h: New test. --- gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c | 17 +++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h | 12 ++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c new file mode 100644 index 0000000..c34e4be --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c @@ -0,0 +1,12 @@ +#include +#include "malloc-ipa-8-lto.h" + +void *wrapped_malloc (size_t size) +{ + return malloc (size); +} + +void wrapped_free (void *ptr) +{ + free (ptr); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c new file mode 100644 index 0000000..c9d7df1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c @@ -0,0 +1,18 @@ +#include +#include "malloc-ipa-8-lto.h" + +boxed_int * +make_boxed_int (int i) +{ + boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int)); + if (!result) + abort (); + result->i = i; + return result; +} + +void +free_boxed_int (boxed_int *bi) +{ + wrapped_free (bi); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c new file mode 100644 index 0000000..d332db1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c @@ -0,0 +1,17 @@ +/* { dg-do link } */ +/* { dg-require-effective-target lto } */ +/* { dg-additional-options "-flto" } */ +/* { dg-additional-sources "malloc-ipa-8-lto-a.c malloc-ipa-8-lto-b.c" } */ + +#include +#include "malloc-ipa-8-lto.h" + +void test (int i) +{ + boxed_int *obj = make_boxed_int (i); + + free_boxed_int (obj); + free (obj); /* { dg-warning "double-free" } */ +} + +int main() { return 0; } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h new file mode 100644 index 0000000..f24eefc --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h @@ -0,0 +1,12 @@ +#include + +extern void *wrapped_malloc (size_t size); +extern void wrapped_free (void *ptr); + +typedef struct boxed_int +{ + int i; +} boxed_int; + +extern boxed_int *make_boxed_int (int i); +extern void free_boxed_int (boxed_int *bi); From patchwork Wed Nov 20 21:13:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514239-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yEekCG33"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="FClXtrWT"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFfb5nGRz9sPL for ; Thu, 21 Nov 2019 08:08:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=KNq /vpvUL+u8zzBE1MRL++6GQCQJLZFRuzhD+k7TVY7OyDFmDqj7ZaHVSBvSUC9PG/n uWGh67kdPyu4einA+8YW3ZpcMoX28vXHsYGSnMY5s9lJcEAcUCFWTPrB/2TA+rn5 eiXqLlIl0bpA0RGipUbSvmOBX+8dkRVPh0EC/c9Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=vvsj7lrDH Eh3AqCzi7r1gKC3/jw=; b=yEekCG334wZCOLcWScrv2suslf43u6LW5uEAA9W3a vEUhFr6pci8veP9na9BKbhkGcFT5Jf9Vzp4qjw6wnRym0IcdoLlVGJmiqWvyH0oT e/6eTKT4yn57grFU4L3FMSM7ZZbAGayxHiIsECpAzYTAmByurwlayWfW8Dgze/RZ WY= Received: (qmail 86835 invoked by alias); 20 Nov 2019 21:07:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86767 invoked by uid 89); 20 Nov 2019 21:07:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=68 X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mgaUBa4akuH1MpiCCW7WuvsBEZ0Wlun6eicOg4anumI=; b=FClXtrWTQNd2PysB4Ox9EbwO1gIl5mk5WUqpowWWPZ74mfiHq3rmwnscfnMQA4hTULp7vs 1mQLbu/wCPrb6p4tfaFNcpS2vaViz9UERP9ULuq5qj8Q4T+tAOjtGK2gkOyrouAiLz061A id3sOgH4+B6M0VcQuRnZo3aBKqEu+II= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-194-4p5poEH-PEOkrG8Z7oVWjw-1; Wed, 20 Nov 2019 16:07:15 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4BFFD100550E for ; Wed, 20 Nov 2019 21:07:14 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58E22106427B; Wed, 20 Nov 2019 21:07:13 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 07/11] [analyzer] Fix missing leak on longjmp past a free Date: Wed, 20 Nov 2019 16:13:46 -0500 Message-Id: <1574284430-8776-8-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch fixes the missing leak report in setjmp-7.c, which failed to report on an unchecked "malloc" result leaking due to a longjmp skipping past its frame to a setjmp in its caller. The root cause issue is that impl_region_model_context::on_state_leak would call the state machine's on_leak vfunc with a tree; this would call back into impl_region_model_context's warn_for_state vfunc, which would add a leak pending_diagnostic if the tree was in the correct sm-state. The latter check was redundant: we already know that the expression in an sm-state for which we ought to report a leak. The check was getting the wrong result: by passing around a tree (for the SSA_NAME for the result of "malloc" in the "middle" frame), the state-lookup was implicitly converting this back to a path_var, and looking for the SSA_NAME's state in the "inner" frame. I looked at updating warn_for_state to take a path_var rather than a tree, but this led to further cleanups being needed in on_transition. This patch takes the simpler approach of having on_leak only be called once a leak of a report-worthy state has been detected, and having it return a pending_diagnostic instance, eliminating the redundant state check. This simplification fixes the missing leak report (although the readability of the report could be improved; it's missing a description of where the longjmp is rewinding to. I'll leave that for a followup). gcc/ChangeLog: * analyzer/engine.cc (impl_region_model_context::on_state_leak): Rather than calling sm.on_leak and having it call back with warn_for_state, get pending_diagnostic from return value of on_leak, and add it directly, avoiding a redundant check of the state of the var. * analyzer/sm-file.cc (fileptr_state_machine::on_leak): Update for simpler API. * analyzer/sm-malloc.cc (malloc_state_machine::on_leak): Likewise. * analyzer/sm-pattern-test.cc (pattern_test_state_machine::on_leak): Delete. * analyzer/sm-sensitive.cc (sensitive_state_machine::on_leak): Delete. * analyzer/sm-taint.cc (taint_state_machine::on_leak): Delete. * analyzer/sm.h (state_machine::on_leak): Convert return type from "void" to "pending_diagnostic *". Drop all parameters except tree. Provide empty base class implementation. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/setjmp-7.c: Remove xfails. * gcc.dg/analyzer/setjmp-7a.c: New test. --- gcc/analyzer/engine.cc | 8 ++- gcc/analyzer/sm-file.cc | 34 ++++------ gcc/analyzer/sm-malloc.cc | 33 ++++------ gcc/analyzer/sm-pattern-test.cc | 17 ----- gcc/analyzer/sm-sensitive.cc | 16 ----- gcc/analyzer/sm-taint.cc | 16 ----- gcc/analyzer/sm.h | 12 ++-- gcc/testsuite/gcc.dg/analyzer/setjmp-7.c | 4 +- gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c | 101 ++++++++++++++++++++++++++++++ 9 files changed, 137 insertions(+), 104 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index c4ca5bf..9936e1e 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -521,8 +521,12 @@ impl_region_model_context::on_state_leak (const state_machine &sm, } } - sm.on_leak (&sm_ctxt, m_enode_for_diag->get_supernode (), m_stmt, - leaked_tree, state); + pending_diagnostic *pd = sm.on_leak (leaked_tree); + if (pd) + m_eg->get_diagnostic_manager ().add_diagnostic + (&sm, m_enode_for_diag, m_enode_for_diag->get_supernode (), + m_stmt, &stmt_finder, + leaked_tree, state, pd); } /* Implementation of region_model_context::on_inherited_svalue vfunc diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc index 4fc308c..f2e8030 100644 --- a/gcc/analyzer/sm-file.cc +++ b/gcc/analyzer/sm-file.cc @@ -52,12 +52,8 @@ public: enum tree_code op, tree rhs) const FINAL OVERRIDE; - void on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state) const FINAL OVERRIDE; bool can_purge_p (state_t s) const FINAL OVERRIDE; + pending_diagnostic *on_leak (tree var) const FINAL OVERRIDE; /* Start state. */ state_t m_start; @@ -299,24 +295,6 @@ fileptr_state_machine::on_condition (sm_context *sm_ctxt, } } -/* Implementation of state_machine::on_leak vfunc for - fileptr_state_machine. - Complain about leaks of FILE * in state 'unchecked' and 'nonnull'. */ - -void -fileptr_state_machine::on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state ATTRIBUTE_UNUSED) - const -{ - sm_ctxt->warn_for_state (node, stmt, var, m_unchecked, - new file_leak (*this, var)); - sm_ctxt->warn_for_state (node, stmt, var, m_nonnull, - new file_leak (*this, var)); -} - /* Implementation of state_machine::can_purge_p vfunc for fileptr_state_machine. Don't allow purging of pointers in state 'unchecked' or 'nonnull' (to avoid false leak reports). */ @@ -327,6 +305,16 @@ fileptr_state_machine::can_purge_p (state_t s) const return s != m_unchecked && s != m_nonnull; } +/* Implementation of state_machine::on_leak vfunc for + fileptr_state_machine, for complaining about leaks of FILE * in + state 'unchecked' and 'nonnull'. */ + +pending_diagnostic * +fileptr_state_machine::on_leak (tree var) const +{ + return new file_leak (*this, var); +} + } // anonymous namespace /* Internal interface to this file. */ diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index 4e02f37..602cb0b 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -54,12 +54,8 @@ public: enum tree_code op, tree rhs) const FINAL OVERRIDE; - void on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state) const FINAL OVERRIDE; bool can_purge_p (state_t s) const FINAL OVERRIDE; + pending_diagnostic *on_leak (tree var) const FINAL OVERRIDE; /* Start state. */ state_t m_start; @@ -761,23 +757,6 @@ malloc_state_machine::on_condition (sm_context *sm_ctxt, } } -/* Implementation of state_machine::on_leak vfunc for malloc_state_machine. - Complain about leaks of pointers in state 'unchecked' and 'nonnull'. */ - -void -malloc_state_machine::on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state ATTRIBUTE_UNUSED) - const -{ - sm_ctxt->warn_for_state (node, stmt, var, m_unchecked, - new malloc_leak (*this, var)); - sm_ctxt->warn_for_state (node, stmt, var, m_nonnull, - new malloc_leak (*this, var)); -} - /* Implementation of state_machine::can_purge_p vfunc for malloc_state_machine. Don't allow purging of pointers in state 'unchecked' or 'nonnull' (to avoid false leak reports). */ @@ -788,6 +767,16 @@ malloc_state_machine::can_purge_p (state_t s) const return s != m_unchecked && s != m_nonnull; } +/* Implementation of state_machine::on_leak vfunc for malloc_state_machine + (for complaining about leaks of pointers in state 'unchecked' and + 'nonnull'). */ + +pending_diagnostic * +malloc_state_machine::on_leak (tree var) const +{ + return new malloc_leak (*this, var); +} + } // anonymous namespace /* Internal interface to this file. */ diff --git a/gcc/analyzer/sm-pattern-test.cc b/gcc/analyzer/sm-pattern-test.cc index cf42cfd..746f2fa 100644 --- a/gcc/analyzer/sm-pattern-test.cc +++ b/gcc/analyzer/sm-pattern-test.cc @@ -56,11 +56,6 @@ public: enum tree_code op, tree rhs) const FINAL OVERRIDE; - void on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state) const FINAL OVERRIDE; bool can_purge_p (state_t s) const FINAL OVERRIDE; private: @@ -136,18 +131,6 @@ pattern_test_state_machine::on_condition (sm_context *sm_ctxt, sm_ctxt->warn_for_state (node, stmt, lhs, m_start, diag); } -void -pattern_test_state_machine::on_leak (sm_context *sm_ctxt ATTRIBUTE_UNUSED, - const supernode *node ATTRIBUTE_UNUSED, - const gimple *stmt ATTRIBUTE_UNUSED, - tree var ATTRIBUTE_UNUSED, - state_machine::state_t state - ATTRIBUTE_UNUSED) - const -{ - /* Empty. */ -} - bool pattern_test_state_machine::can_purge_p (state_t s ATTRIBUTE_UNUSED) const { diff --git a/gcc/analyzer/sm-sensitive.cc b/gcc/analyzer/sm-sensitive.cc index f634b8f..414dd56 100644 --- a/gcc/analyzer/sm-sensitive.cc +++ b/gcc/analyzer/sm-sensitive.cc @@ -54,11 +54,6 @@ public: enum tree_code op, tree rhs) const FINAL OVERRIDE; - void on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state) const FINAL OVERRIDE; bool can_purge_p (state_t s) const FINAL OVERRIDE; private: @@ -181,17 +176,6 @@ sensitive_state_machine::on_condition (sm_context *sm_ctxt ATTRIBUTE_UNUSED, /* Empty. */ } -void -sensitive_state_machine::on_leak (sm_context *sm_ctxt ATTRIBUTE_UNUSED, - const supernode *node ATTRIBUTE_UNUSED, - const gimple *stmt ATTRIBUTE_UNUSED, - tree var ATTRIBUTE_UNUSED, - state_machine::state_t state ATTRIBUTE_UNUSED) - const -{ - /* Empty. */ -} - bool sensitive_state_machine::can_purge_p (state_t s ATTRIBUTE_UNUSED) const { diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc index c664a54..59b9171 100644 --- a/gcc/analyzer/sm-taint.cc +++ b/gcc/analyzer/sm-taint.cc @@ -55,11 +55,6 @@ public: enum tree_code op, tree rhs) const FINAL OVERRIDE; - void on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state) const FINAL OVERRIDE; bool can_purge_p (state_t s) const FINAL OVERRIDE; /* Start state. */ @@ -310,17 +305,6 @@ taint_state_machine::on_condition (sm_context *sm_ctxt, } } -void -taint_state_machine::on_leak (sm_context *sm_ctxt ATTRIBUTE_UNUSED, - const supernode *node ATTRIBUTE_UNUSED, - const gimple *stmt ATTRIBUTE_UNUSED, - tree var ATTRIBUTE_UNUSED, - state_machine::state_t state ATTRIBUTE_UNUSED) - const -{ - /* Empty. */ -} - bool taint_state_machine::can_purge_p (state_t s ATTRIBUTE_UNUSED) const { diff --git a/gcc/analyzer/sm.h b/gcc/analyzer/sm.h index 0a89f8a..b35d8c5 100644 --- a/gcc/analyzer/sm.h +++ b/gcc/analyzer/sm.h @@ -73,17 +73,17 @@ public: const gimple *stmt, tree lhs, enum tree_code op, tree rhs) const = 0; - virtual void on_leak (sm_context *sm_ctxt, - const supernode *node, - const gimple *stmt, - tree var, - state_machine::state_t state) const = 0; - /* Return true if it safe to discard the given state (to help when simplifying state objects). States that need leak detection should return false. */ virtual bool can_purge_p (state_t s) const = 0; + /* Called when VAR leaks (and !can_purge_p). */ + virtual pending_diagnostic *on_leak (tree var ATTRIBUTE_UNUSED) const + { + return NULL; + } + void validate (state_t s) const; protected: diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c index 2d44926..ee4183d 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-7.c @@ -8,12 +8,12 @@ static jmp_buf env; static void inner (void) { - longjmp (env, 1); /* { dg-warning "leak of 'ptr'" "" { xfail *-*-* } } */ + longjmp (env, 1); /* { dg-warning "leak of 'ptr'" } */ } static void middle (void) { - void *ptr = malloc (1024); /* { dg-message "allocated here" "" { xfail *-*-* } } */ + void *ptr = malloc (1024); /* { dg-message "allocated here" } */ inner (); free (ptr); } diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c new file mode 100644 index 0000000..1d5fc2e --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c @@ -0,0 +1,101 @@ +/* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-nn-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ + +#include +#include + +extern void foo (int); + +static jmp_buf env; + +static void inner (void) +{ + longjmp (env, 1); /* { dg-warning "leak of 'ptr'" } */ +} + +static void middle (void) +{ + void *ptr = malloc (1024); + inner (); + free (ptr); +} + +void outer (void) +{ + int i; + + foo (0); + + i = setjmp(env); + + if (i == 0) + { + foo (1); + middle (); + } + + foo (3); +} + +/* { dg-begin-multiline-output "" } + NN | longjmp (env, 1); + | ^~~~~~~~~~~~~~~~ + 'outer': event 1 + | + | NN | void outer (void) + | | ^~~~~ + | | | + | | (1) entry to 'outer' + | + 'outer': event 2 + | + | NN | i = setjmp(env); + | | ^~~~~~ + | | | + | | (2) 'setjmp' called here + | + 'outer': events 3-5 + | + | NN | if (i == 0) + | | ^ + | | | + | | (3) following 'true' branch (when 'i == 0')... + | NN | { + | NN | foo (1); + | | ~~~~~~~ + | | | + | | (4) ...to here + | NN | middle (); + | | ~~~~~~~~~ + | | | + | | (5) calling 'middle' from 'outer' + | + +--> 'middle': events 6-8 + | + | NN | static void middle (void) + | | ^~~~~~ + | | | + | | (6) entry to 'middle' + | NN | { + | NN | void *ptr = malloc (1024); + | | ~~~~~~~~~~~~~ + | | | + | | (7) allocated here + | NN | inner (); + | | ~~~~~~~~ + | | | + | | (8) calling 'inner' from 'middle' + | + +--> 'inner': events 9-10 + | + | NN | static void inner (void) + | | ^~~~~ + | | | + | | (9) entry to 'inner' + | NN | { + | NN | longjmp (env, 1); + | | ~~~~~~~~~~~~~~~~ + | | | + | | (10) 'ptr' leaks here; was allocated at (7) + | + { dg-end-multiline-output "" } */ +// TODO: show the rewind to the setjmp From patchwork Wed Nov 20 21:13:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514241-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OQgQ641I"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="XNZX5WmP"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFg40m2jz9sPL for ; Thu, 21 Nov 2019 08:09:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=B+2 Fjx0oOIiF4GeBN8rWWgLn9s49UgC1V/Q6Wotl753/btTA10CESF/UyWVAEAEEMAg Afu9ZUQ8RwoI/OBjondPjsPl1NJW0Wm6z4jMF6WBbVWgZqn++4RY6bUKQ1/w85pU J2FBDJRNm/tL1t9HOEd2pAk9Vy4m8RS7MpLKWtcs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=8ywP626Nj udUeCf+dzUeNDVnMnY=; b=OQgQ641IVro98LsZW15/sOney5PXb8O+prtksGe91 gVTXdUFqprQY+eSOVl9t4LBemaD3mai/jbnE55lxqmIeDInE2isS/xZGV6Oz6exE TzeM03kHl/9QikSW8CnQXxag55wgudbc7HzVXKCic/aHPW9liOlWbi5HMZZAtpcF tg= Received: (qmail 87057 invoked by alias); 20 Nov 2019 21:07:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86971 invoked by uid 89); 20 Nov 2019 21:07:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.1 spammy=association, POINT, sk:new_reg X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ozwD/WzuQhC7jt1vTlAX10RkaNP7F7CduQ5yLAr0gV8=; b=XNZX5WmPU9FK1GScTuPnIh1vAASdU3/bYFnM6mrNvgreupDmSQPI3qX/R5JZK3xsINMKSI ZnLo1T87oIhAde4LHmxsPz2eqXgDadK28Mt1aydTzs/+JhmIydasT/1zREet2h5KWz4Dbb vPD3a5XfbWvkZtn2KWuIo06PXzEW/jg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-409-czjzrlaoNW-kzWwg0B2daQ-1; Wed, 20 Nov 2019 16:07:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 907C0800A02 for ; Wed, 20 Nov 2019 21:07:15 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D6EE106427B; Wed, 20 Nov 2019 21:07:14 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 08/11] [analyzer] Show rewind destination for leaks due to longjmp Date: Wed, 20 Nov 2019 16:13:47 -0500 Message-Id: <1574284430-8776-9-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch adds some special-case logic to how paths are generated so that leaks due to longjmp rewinding past a frame now show where the longjmp rewinds to (longjmp and setjmp are already something of a special-case so this seems reasonable). A colorized LTO example of the output can be seen at: https://dmalcolm.fedorapeople.org/gcc/2019-11-18/lto-longjmp-leak-demo.html gcc/ChangeLog: * analyzer/diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Initialize new field m_trailing_eedge. (diagnostic_manager::emit_saved_diagnostic): If m_trailing_eedge is set, use it to add extra events after the "final" event. * analyzer/diagnostic-manager.h (saved_diagnostic::operator==): Compare m_trailing_eedge fields. (saved_diagnostic::m_trailing_eedge): New field. (diagnostic_manager::get_num_diagnostics): New accessor. (diagnostic_manager::get_saved_diagnostic): New accessor. * analyzer/engine.cc (exploded_node::on_longjmp): Set m_trailing_edge on any diagnostics saved when handling region_model::on_longjmp. (exploded_graph::add_edge): Return the newly-created eedge. * analyzer/exploded-graph.h (exploded_graph::add_edge): Convert return type from void to exploded_edge *. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/setjmp-7a.c: Update expected multiline output to include a final pair of events showing the longjmp and the setjmp that it rewinds to. --- gcc/analyzer/diagnostic-manager.cc | 9 ++++- gcc/analyzer/diagnostic-manager.h | 13 ++++++- gcc/analyzer/engine.cc | 56 ++++++++++++++++++++++++++++--- gcc/analyzer/exploded-graph.h | 8 ++--- gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c | 13 +++++-- 5 files changed, 86 insertions(+), 13 deletions(-) diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index fae38c7..926900b 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -47,7 +47,7 @@ saved_diagnostic::saved_diagnostic (const state_machine *sm, outlive that. */ m_stmt_finder (stmt_finder ? stmt_finder->clone () : NULL), m_var (var), m_state (state), - m_d (d) + m_d (d), m_trailing_eedge (NULL) { gcc_assert (m_stmt || m_stmt_finder); @@ -427,6 +427,13 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg, emission_path.add_final_event (sd.m_sm, epath.get_final_enode (), stmt, sd.m_var, sd.m_state); + /* The "final" event might not be final; if the saved_diagnostic has a + trailing eedge stashed, add any events for it. This is for use + in handling longjmp, to show where a longjmp is rewinding to. */ + if (sd.m_trailing_eedge) + add_events_for_eedge (*sd.m_trailing_eedge, eg.get_ext_state (), + &emission_path); + emission_path.prepare_for_emission (sd.m_d); gcc_rich_location rich_loc (stmt->location); diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index 0f4444c..8591d2e 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -45,7 +45,8 @@ public: /* We don't compare m_stmt_finder. */ && m_var == other.m_var && m_state == other.m_state - && m_d->equal_p (*other.m_d)); + && m_d->equal_p (*other.m_d) + && m_trailing_eedge == other.m_trailing_eedge); } //private: @@ -57,6 +58,7 @@ public: tree m_var; state_machine::state_t m_state; pending_diagnostic *m_d; + exploded_edge *m_trailing_eedge; }; /* A class with responsibility for saving pending diagnostics, so that @@ -93,6 +95,15 @@ public: const gimple *stmt, int num_dupes); + unsigned get_num_diagnostics () const + { + return m_saved_diagnostics.length (); + } + saved_diagnostic *get_saved_diagnostic (unsigned idx) + { + return m_saved_diagnostics[idx]; + } + private: void build_emission_path (const exploded_graph &eg, const exploded_path &epath, diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 9936e1e..aa4a359 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -1083,6 +1083,13 @@ exploded_node::on_longjmp (exploded_graph &eg, >= setjmp_point.get_stack_depth ()); /* Update the state for use by the destination node. */ + + /* Stash the current number of diagnostics so that we can update + any that this adds to show where the longjmp is rewinding to. */ + + diagnostic_manager *dm = &eg.get_diagnostic_manager (); + unsigned prev_num_diagnostics = dm->get_num_diagnostics (); + new_region_model->on_longjmp (longjmp_call, setjmp_call, setjmp_point.get_stack_depth (), ctxt); @@ -1095,9 +1102,46 @@ exploded_node::on_longjmp (exploded_graph &eg, /* Create custom exploded_edge for a longjmp. */ if (next) - eg.add_edge (const_cast (this), next, NULL, - change, - new rewind_info_t (enode_origin)); + { + exploded_edge *eedge + = eg.add_edge (const_cast (this), next, NULL, + change, + new rewind_info_t (enode_origin)); + + /* For any diagnostics that were queued here (such as leaks) we want + the checker_path to show the rewinding events after the "final event" + so that the user sees where the longjmp is rewinding to (otherwise the + path is meaningless). + + For example, we want to emit something like: + | NN | { + | NN | longjmp (env, 1); + | | ~~~~~~~~~~~~~~~~ + | | | + | | (10) 'ptr' leaks here; was allocated at (7) + | | (11) rewinding from 'longjmp' in 'inner'... + | + <-------------+ + | + 'outer': event 12 + | + | NN | i = setjmp(env); + | | ^~~~~~ + | | | + | | (12) ...to 'setjmp' in 'outer' (saved at (2)) + + where the "final" event above is event (10), but we want to append + events (11) and (12) afterwards. + + Do this by setting m_trailing_eedge on any diagnostics that were + just saved. */ + unsigned num_diagnostics = dm->get_num_diagnostics (); + for (unsigned i = prev_num_diagnostics; i < num_diagnostics; i++) + { + saved_diagnostic *sd = dm->get_saved_diagnostic (i); + sd->m_trailing_eedge = eedge; + } + } } /* Subroutine of exploded_graph::process_node for finding the successors @@ -1768,9 +1812,10 @@ exploded_graph::get_or_create_node (const program_point &point, /* Add an exploded_edge from SRC to DEST, recording its association with SEDGE (which may be NULL), and, if non-NULL, taking ownership - of REWIND_INFO. */ + of REWIND_INFO. + Return the newly-created eedge. */ -void +exploded_edge * exploded_graph::add_edge (exploded_node *src, exploded_node *dest, const superedge *sedge, const state_change &change, @@ -1778,6 +1823,7 @@ exploded_graph::add_edge (exploded_node *src, exploded_node *dest, { exploded_edge *e = new exploded_edge (src, dest, sedge, change, rewind_info); digraph::add_edge (e); + return e; } /* Ensure that this graph has per-program_point-data for POINT; diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index f97d2b6..97e1005 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -627,10 +627,10 @@ public: exploded_node *get_or_create_node (const program_point &point, const program_state &state, state_change *change); - void add_edge (exploded_node *src, exploded_node *dest, - const superedge *sedge, - const state_change &change, - rewind_info_t *rewind_info = NULL); + exploded_edge *add_edge (exploded_node *src, exploded_node *dest, + const superedge *sedge, + const state_change &change, + rewind_info_t *rewind_info = NULL); per_program_point_data * get_or_create_per_program_point_data (const program_point &); diff --git a/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c b/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c index 1d5fc2e..6f99df5 100644 --- a/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c +++ b/gcc/testsuite/gcc.dg/analyzer/setjmp-7a.c @@ -85,7 +85,7 @@ void outer (void) | | | | | (8) calling 'inner' from 'middle' | - +--> 'inner': events 9-10 + +--> 'inner': events 9-11 | | NN | static void inner (void) | | ^~~~~ @@ -96,6 +96,15 @@ void outer (void) | | ~~~~~~~~~~~~~~~~ | | | | | (10) 'ptr' leaks here; was allocated at (7) + | | (11) rewinding from 'longjmp' in 'inner'... | + <-------------+ + | + 'outer': event 12 + | + | NN | i = setjmp(env); + | | ^~~~~~ + | | | + | | (12) ...to 'setjmp' in 'outer' (saved at (2)) + | { dg-end-multiline-output "" } */ -// TODO: show the rewind to the setjmp From patchwork Wed Nov 20 21:13:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514240-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fKeQMhik"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="O1YT/wyg"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFfq2r9tz9sPL for ; Thu, 21 Nov 2019 08:08:51 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=yUc PY2ZtH3lIdVv/a2ILK5jrwsl1De9uvFgV1lxbvqQP4sj1WXZenQ+WEv1YxTHEZkB YGDbiy867ihsTezvIGzkiul4ZLUJYNk0uxHgC4MvdObBfmRzE39j7YbhpSoQR4qg uJ1jaqX2lW/0t0PLfU1k2gaeY6TO1v7q7fIjNTQk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=+c01ij54W 0DcD+odFAUz/RqACK0=; b=fKeQMhiknvp1xOtmQMLImM40Ib687LPHLMwy0USBZ oSk2w5KQS3JIGdCS5axwpcZEUKo32rXSwtlJL3ZQlADk+aeqDwVyZ3aC5FUdTJ3A XwIrx2saZ96n2AvXdcS6FU0KHX58V1V+R69u8YM5YV2YW2tUFVFgiCNZbhAoSikM zc= Received: (qmail 86927 invoked by alias); 20 Nov 2019 21:07:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 86852 invoked by uid 89); 20 Nov 2019 21:07:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1440, *pp X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2DMofitlWcgtztf4xKFpzpY0Id4PTsFYU1xke3PGgF4=; b=O1YT/wygnVEWlcTk7N3Xzewm/mFcrSmy5imbioRPTwJbqloyU+mUlHy9jRNNEIr1KAYzN5 y23k/m6Gy0m+mskXyQ7OKcwo00GaN+8lm0BnIj5+jBWnL4Af2VNUKgfSaLLXuhoUAhRt2J MHKkxYFjMa9xYAujhFkszTouetQYc3k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-408-b_sEjrgcPfKIuIXF2Fp0sA-1; Wed, 20 Nov 2019 16:07:17 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E35502F2B for ; Wed, 20 Nov 2019 21:07:16 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBE04106427B; Wed, 20 Nov 2019 21:07:15 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 09/11] [analyzer] Add checker_path::debug Date: Wed, 20 Nov 2019 16:13:48 -0500 Message-Id: <1574284430-8776-10-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch adds a new debugging function. gcc/ChangeLog: * analyzer/checker-path.cc (checker_path::debug): New member function. * analyzer/checker-path.h (checker_path::debug): New decl. --- gcc/analyzer/checker-path.cc | 19 +++++++++++++++++++ gcc/analyzer/checker-path.h | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 5302504..0a18406 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -883,6 +883,25 @@ checker_path::maybe_log (logger *logger, const char *desc) const } } +/* Print a multiline form of this path to STDERR. */ + +DEBUG_FUNCTION void +checker_path::debug () const +{ + checker_event *e; + int i; + FOR_EACH_VEC_ELT (m_events, i, e) + { + label_text event_desc (e->get_desc (false)); + fprintf (stderr, + "[%i]: %s \"%s\"\n", + i, + event_kind_to_string (m_events[i]->m_kind), + event_desc.m_buffer); + event_desc.maybe_free (); + } +} + /* Add a warning_event to the end of this path. */ void diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h index f042f47..916e5a7 100644 --- a/gcc/analyzer/checker-path.h +++ b/gcc/analyzer/checker-path.h @@ -499,8 +499,8 @@ public: return *m_events[idx]; } - void dump (pretty_printer *pp) const; + void debug () const; void maybe_log (logger *logger, const char *desc) const; From patchwork Wed Nov 20 21:13:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198531 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514242-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qn/0kn9m"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="MmZPP8aR"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFgN51v1z9s7T for ; Thu, 21 Nov 2019 08:09:19 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=JXB NzmUbubWjGaoVOfPA7fvpOubGmO+Z8kk8yPX3GP4kFV82kzkfMXh9Y41lE+3zbhZ 5iHWsJL/I+ZCxA28aIvOKPAN1TwfT5+zkg+2NsgH1/QupH/lPfondjv2JECwafDB GSKNkk9uyTBn9u33SlZetNzJOMqsau/9R2abfqYU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=WqsO6Q/Pw FQmmeOYwmpTzQh/Gn0=; b=qn/0kn9mupOEhofw5t4/mCEeTKVEa1lsUsoK7/Gm+ 7L1tUXO2YG4Jy+LSgFuw4DoKryC8tgaUNLdNC2TZBDim0qmM0tFZHZKAtO8dPrNM brU2negTasTs5hfmWbrvFmbpKoS6/i2G0l2ZjN7krWVaSJFtxFqL+Xa/MKsGLWpc ZQ= Received: (qmail 87287 invoked by alias); 20 Nov 2019 21:07:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 87227 invoked by uid 89); 20 Nov 2019 21:07:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=1893, 1583, prunes X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+dfPIpU6HYSmv83veM1nDCP0aSB/ljHtekHRBVbI11Y=; b=MmZPP8aRH3rUkYbygeLYmaC4vCZJgf5lVqKZ/bTLhzCPQVVdn7sBuqPE1/7S0E2E62yfjL TMwCFMmKe5iPY0xWJcjmld+TBSgMeORBLKcQoXz5ex22hi81ikJ4iy99ECNGPGvQpoJXkT W9NMzymXakdvDia8TkLOXF24+mVaF/I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-183-gSCIT21fP0yFX9PvbkyxtQ-1; Wed, 20 Nov 2019 16:07:19 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31E5A800054 for ; Wed, 20 Nov 2019 21:07:18 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47449106427B; Wed, 20 Nov 2019 21:07:17 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 10/11] [analyzer] Fix issues in diagnostic_manager::prune_path Date: Wed, 20 Nov 2019 16:13:49 -0500 Message-Id: <1574284430-8776-11-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes There was a bad upper limit in diagnostic_manager::prune_path's test for pruning redundant interprocedural pass information, leading to an ICE. Additional, the test for pruning [..., call, function-entry, return, ...] triples doesn't work for -fanalyzer-verbosity=0, which doesn't generate function-entry events, leading to cases where -fanalyzer-verbosity=0 could be more verbose than higher limits, e.g.: 'test_3': events 1-4 | | NN | free (ptr); | | ^~~~~~~~~~ | | | | | (1) first 'free' here | NN | called_by_test_3 (); | | ~~~~~~~~~~~~~~~~~~~ | | | | | (2) calling 'called_by_test_3' from 'test_3' | | (3) returning to 'test_3' from 'called_by_test_3' | NN | free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */ | | ~~~~~~~~~~ | | | | | (4) second 'free' here; first 'free' was at (1) | where the call/return would be pruned at higher verbosities. This patch fixes the limits, and prunes the case of a [call, return] pair. gcc/ChangeLog: * analyzer/diagnostic-manager.cc (diagnostic_manager::prune_path): When pruning [..., call, function-entry, return, ...] triples, fix the bounds test and move it inside the loop. Also test for [..., call, return, ...] pairs. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/analyzer-verbosity-0.c: Add coverage for pruning a call/return to an empty function. * gcc.dg/analyzer/analyzer-verbosity-1.c: Likewise. * gcc.dg/analyzer/analyzer-verbosity-2.c: Likewise. --- gcc/analyzer/diagnostic-manager.cc | 32 ++++++++++++++++++++-- .../gcc.dg/analyzer/analyzer-verbosity-0.c | 29 ++++++++++++++++++++ .../gcc.dg/analyzer/analyzer-verbosity-1.c | 30 ++++++++++++++++++++ .../gcc.dg/analyzer/analyzer-verbosity-2.c | 30 ++++++++++++++++++++ 4 files changed, 118 insertions(+), 3 deletions(-) diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 926900b..8cd4507 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -1076,10 +1076,12 @@ diagnostic_manager::prune_path (checker_path *path, do { changed = false; - int idx = path->m_events.length () - 3; - while (idx >= 0 && idx < (signed)path->m_events.length ()) + int idx = path->m_events.length () - 1; + while (idx >= 0) { - if (path->m_events[idx]->is_call_p () + /* Prune [..., call, function-entry, return, ...] triples. */ + if (idx + 2 < (signed)path->m_events.length () + && path->m_events[idx]->is_call_p () && path->m_events[idx + 1]->is_function_entry_p () && path->m_events[idx + 2]->is_return_p ()) { @@ -1095,7 +1097,31 @@ diagnostic_manager::prune_path (checker_path *path, path->delete_event (idx + 1); path->delete_event (idx); changed = true; + idx--; + continue; } + + /* Prune [..., call, return, ...] pairs + (for -fanalyzer-verbosity=0). */ + if (idx + 1 < (signed)path->m_events.length () + && path->m_events[idx]->is_call_p () + && path->m_events[idx + 1]->is_return_p ()) + { + if (get_logger ()) + { + label_text desc (path->m_events[idx]->get_desc (false)); + log ("filtering events %i-%i:" + " irrelevant call/return: %s", + idx, idx + 1, desc.m_buffer); + desc.maybe_free (); + } + path->delete_event (idx + 1); + path->delete_event (idx); + changed = true; + idx--; + continue; + } + idx--; } diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c b/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c index 98200b3..1103cc6 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c +++ b/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-0.c @@ -131,3 +131,32 @@ void test_2 (void *ptr, int a, int b) // TODO: range cases +/* The call/return to this function shouldn't appear in the path. */ + +void called_by_test_3 (void) +{ +} + +void test_3 (void *ptr) +{ + free (ptr); + called_by_test_3 (); + free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */ +} + +/* { dg-begin-multiline-output "" } + NN | free (ptr); + | ^~~~~~~~~~ + 'test_3': events 1-2 + | + | NN | free (ptr); + | | ^~~~~~~~~~ + | | | + | | (1) first 'free' here + | NN | called_by_test_3 (); + | NN | free (ptr); + | | ~~~~~~~~~~ + | | | + | | (2) second 'free' here; first 'free' was at (1) + | + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c b/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c index 7e437bb..80039d5 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-1.c @@ -158,3 +158,33 @@ void test_2 (void *ptr, int a, int b) | | (8) second 'free' here; first 'free' was at (4) | { dg-end-multiline-output "" } */ + +/* The call/return to this function shouldn't appear in the path. */ + +void called_by_test_3 (void) +{ +} + +void test_3 (void *ptr) +{ + free (ptr); + called_by_test_3 (); + free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */ +} + +/* { dg-begin-multiline-output "" } + NN | free (ptr); + | ^~~~~~~~~~ + 'test_3': events 1-2 + | + | NN | free (ptr); + | | ^~~~~~~~~~ + | | | + | | (1) first 'free' here + | NN | called_by_test_3 (); + | NN | free (ptr); + | | ~~~~~~~~~~ + | | | + | | (2) second 'free' here; first 'free' was at (1) + | + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c b/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c index 2c9e5da..9b87d43 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c +++ b/gcc/testsuite/gcc.dg/analyzer/analyzer-verbosity-2.c @@ -189,3 +189,33 @@ void test_2 (void *ptr, int a, int b) { dg-end-multiline-output "" } */ // TODO: range cases + +/* The call/return to this function shouldn't appear in the path. */ + +void called_by_test_3 (void) +{ +} + +void test_3 (void *ptr) +{ + free (ptr); + called_by_test_3 (); + free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */ +} + +/* { dg-begin-multiline-output "" } + NN | free (ptr); + | ^~~~~~~~~~ + 'test_3': events 1-2 + | + | NN | free (ptr); + | | ^~~~~~~~~~ + | | | + | | (1) first 'free' here + | NN | called_by_test_3 (); + | NN | free (ptr); + | | ~~~~~~~~~~ + | | | + | | (2) second 'free' here; first 'free' was at (1) + | + { dg-end-multiline-output "" } */ From patchwork Wed Nov 20 21:13:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1198532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514243-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="K1U3l7Zd"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="IBRJMZc3"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JFgg0Zptz9s7T for ; Thu, 21 Nov 2019 08:09:34 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=sX+ NxZ9tlK1ZbP4hUPvhxXdYxcU6GPnqNJogBszBUSbJWNtT91KO1YWhpvWxUYKbqIJ 9NjJRLdr/a22fnn7X0Rjwd9Ncw7R4m4pHK6dJ2suA3xMvrhAJtffhDBUqz5qrfuQ 3qSlOkxwsGCvE7m6dcUQ7J9wOIrrIaft5GUyzwTk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=WktkU4Xuh YO8sWg8kutFXhszGR4=; b=K1U3l7Zds2AzyweCZ6uS+AZgY2KWt5cZYLRvfe14M 660Ddb5ci2AxFdeRz7qqJBDj9TwbDGtz42wxVjW4gw+UecYRmLyOGYhqeZsHJOTb 0SIVpevM5u0pla55NZWZVpzGs2JFa5Q0O3qhEP2IlvEIamxxlsll/NMfO6jFGLeC 9o= Received: (qmail 87753 invoked by alias); 20 Nov 2019 21:07:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 87358 invoked by uid 89); 20 Nov 2019 21:07:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 20 Nov 2019 21:07:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574284042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k5YnM6ezEUEucc3A+BdwjEcv5vljMKsSnvl/71FFKfg=; b=IBRJMZc3/ZAn/jomamTVKXRBoAOZXjZJW95+ilXuFH5IPfrvfqE2Z1w0+wqjB8oYGNM9e2 LNUylRrdVRWipVnVBA36J2hItP78/EhWhM88EuJ+fpkOJ93FKw0tRcRttlrc0rPo/FGwPf BAMFHJVzDjet+s1KNUjRNdhpOAXPNuA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-1eRpnFoZOrqxmA_rYxRNog-1; Wed, 20 Nov 2019 16:07:20 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84A74800A02 for ; Wed, 20 Nov 2019 21:07:19 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-19.phx2.redhat.com [10.3.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96893106F957; Wed, 20 Nov 2019 21:07:18 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 11/11] [analyzer] Updates to internal documentation Date: Wed, 20 Nov 2019 16:13:50 -0500 Message-Id: <1574284430-8776-12-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> References: <1574284430-8776-1-git-send-email-dmalcolm@redhat.com> X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes gcc/ChangeLog: * doc/analyzer.texi (Analyzer Paths): Add path pruning and precision-of-wording vfuncs. (Debugging the Analyzer): Consolidate duplicated material. --- gcc/doc/analyzer.texi | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/gcc/doc/analyzer.texi b/gcc/doc/analyzer.texi index adf375a..3f5999f 100644 --- a/gcc/doc/analyzer.texi +++ b/gcc/doc/analyzer.texi @@ -342,9 +342,39 @@ each duplicate warning's shortest path is feasible, rejecting any warnings for which the shortest path is infeasible (which could lead to false negatives). -We use the shortest feasible path through the exploded_graph (a list of -edges) to build a @code{diagnostic_path} (a list of events for the -diagnostic subsystem). +We use the shortest feasible @code{exploded_path} through the +@code{exploded_graph} (a list of @code{exploded_edge *}) to build a +@code{diagnostic_path} (a list of events for the diagnostic subsystem) - +specifically a @code{checker_path}. + +Having built the @code{checker_path}, we prune it to try to eliminate +events that aren't relevant, to minimize how much the user has to read. + +After pruning, we notify each event in the path of its ID and record the +IDs of interesting events, allowing for events to refer to other events +in their descriptions. The @code{pending_diagnostic} class has various +vfuncs to support emitting more precise descriptions, so that e.g. + +@itemize @bullet +@item +a deref-of-unchecked-malloc diagnostic might use: +@smallexample + returning possibly-NULL pointer to 'make_obj' from 'allocator' +@end smallexample +for a @code{return_event} to make it clearer how the unchecked value moves +from callee back to caller +@item +a double-free diagnostic might use: +@smallexample + second 'free' here; first 'free' was at (3) +@end smallexample +and a use-after-free might use +@smallexample + use after 'free' here; memory was freed at (2) +@end smallexample +@end itemize + +At this point we can emit the diagnostic. @subsection Limitations @@ -442,21 +472,18 @@ will dump just the number of nodes, and their IDs. will also dump all of the states within those nodes. -@code{region_model::get_value_by_name} can be used when inserting custom -debugging code (e.g. adding it @code{region_model::validate} to detect the -point at which a named variable acquires an unexpected state). - @subsection Other Debugging Techniques One approach when tracking down where a particular bogus state is introduced into the @code{exploded_graph} is to add custom code to @code{region_model::validate}. -For example, this custom code breaks with an assertion failure when a -variable called @code{ptr} acquires a value that's unknown: +For example, this custom code (added to @code{region_model::validate}) +breaks with an assertion failure when a variable called @code{ptr} +acquires a value that's unknown, using +@code{region_model::get_value_by_name} to locate the variable @smallexample - /* Find a variable matching "ptr". */ svalue_id sid = get_value_by_name ("ptr"); if (!sid.null_p ())