From patchwork Sat Dec 21 00:25:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1214389 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-516424-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="AJk7E/dd"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="XZ/Am1xZ"; 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 47fmcJ3gK0z9sPW for ; Sat, 21 Dec 2019 11:25: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:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=YENclrbirbFoYshQ gErDTA9JJL9l7MdRntqcOkNnlLBRKAVXFNPZmBJbTA1n5VL4c9YpIz6Kl4iUmSc3 BtP99wtfQfcEwCecpvQILWhY39Bdak7fHg1ujLnPVOyH1OGS3ZT87Gh/SVDpaoB3 zSZ8rBOOGNz8mHJgl/+cLvx0Hag= 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:mime-version:content-type :content-transfer-encoding; s=default; bh=YVDOD/LOiwPJmU4X4mAQOu xo8xs=; b=AJk7E/ddfLqo5Ggw4s4p5B+vIK8k60HP+LM7RlppErE8smFRkEknNV PGnmlRrsXTzgo/CYKdetxLrxIp5m9dsdZFywb6iQbb12S4DeKwA2YdGXZPD0RMRn uPXSoM3qZnZCC1pO4o8sqtm2/oUOLsR0mbPfM1vshRmhxDQ/jXZwU= Received: (qmail 92192 invoked by alias); 21 Dec 2019 00:25:45 -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 92182 invoked by uid 89); 21 Dec 2019 00:25:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.1 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=BORDER 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; Sat, 21 Dec 2019 00:25:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576887942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ds4Ue+k2wMtMpTtUU1wquX7iGtycuHcwDOWfzow33PI=; b=XZ/Am1xZYA1SuDDE4Q37Qj3GWLrOXfovdt4376z3rvZpVAz0MWC2Dg8TViK8DSo9/2fTtJ LAlaq3l81tgmecWW5cKM314C8R9KYy4L0opOnk++ywvQQp85PkcoQOTxmZwan+umoFgzuA OnQe9532+iSdHYVkLyv9iEiA2W/tT/Y= 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-395-8Iz0g2OhOhOdnr5toeITWw-1; Fri, 20 Dec 2019 19:25:41 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2C0B4800053 for ; Sat, 21 Dec 2019 00:25:40 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-41.phx2.redhat.com [10.3.117.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE4F45D9CA; Sat, 21 Dec 2019 00:25:39 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] analyzer: ensure .dot output is valid for an empty BB Date: Fri, 20 Dec 2019 19:25:37 -0500 Message-Id: <20191221002537.4362-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch fixes an issue with the output of -fdump-analyzer-supergraph on BBs with no statements, where the resulting files were unreadable by dot e.g.: Error: syntax error in line 1 ...
... in label of node node_10 Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to the dmalcolm/analyzer branch on the GCC git mirror. gcc/analyzer/ChangeLog: * supergraph.cc (supernode::dump_dot): Ensure that the TABLE element has at least one TR. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/dot-output.c: Add test coverage for a BB with no statements. --- gcc/analyzer/supergraph.cc | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/dot-output.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc index ba7f7c6d2994..dc20a0234cb6 100644 --- a/gcc/analyzer/supergraph.cc +++ b/gcc/analyzer/supergraph.cc @@ -444,6 +444,8 @@ supernode::dump_dot (graphviz_out *gv, const dump_args_t &args) const pp_string (pp, ""); pp_write_text_to_stream (pp); + bool had_row = false; + if (m_returning_call) { gv->begin_tr (); @@ -458,18 +460,22 @@ supernode::dump_dot (graphviz_out *gv, const dump_args_t &args) const if (args.m_node_annotator) args.m_node_annotator->add_stmt_annotations (gv, m_returning_call); pp_newline (pp); + + had_row = true; } if (entry_p ()) { pp_string (pp, ""); pp_newline (pp); + had_row = true; } if (return_p ()) { pp_string (pp, ""); pp_newline (pp); + had_row = true; } /* Phi nodes. */ @@ -486,6 +492,7 @@ supernode::dump_dot (graphviz_out *gv, const dump_args_t &args) const args.m_node_annotator->add_stmt_annotations (gv, stmt); pp_newline (pp); + had_row = true; } /* Statements. */ @@ -502,6 +509,15 @@ supernode::dump_dot (graphviz_out *gv, const dump_args_t &args) const args.m_node_annotator->add_stmt_annotations (gv, stmt); pp_newline (pp); + had_row = true; + } + + /* Graphviz requires a TABLE element to have at least one TR + (and each TR to have at least one TD). */ + if (!had_row) + { + pp_string (pp, ""); + pp_newline (pp); } pp_string (pp, "
ENTRY
EXIT
(empty)
>];\n\n"); diff --git a/gcc/testsuite/gcc.dg/analyzer/dot-output.c b/gcc/testsuite/gcc.dg/analyzer/dot-output.c index 586e14421e0e..25cb31f2d894 100644 --- a/gcc/testsuite/gcc.dg/analyzer/dot-output.c +++ b/gcc/testsuite/gcc.dg/analyzer/dot-output.c @@ -27,6 +27,22 @@ int *test (int *buf, int n, int *out) return result; } +/* Test that we can generate valid .dot files given a BB with no + statements. */ +extern int func (); +int test_2 (void) +{ + int c1; + do + { + c1 = func (); + if (c1 == '\0') + break; + } + while (c1); + return c1; +} + /* { dg-final { dg-check-dot "dot-output.c.callgraph.dot" } } */ /* { dg-final { dg-check-dot "dot-output.c.eg.dot" } } */ /* { dg-final { dg-check-dot "dot-output.c.state-purge.dot" } } */