From patchwork Wed Dec 4 16:25:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1204258 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-515134-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (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="gpa0JzIW"; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="NzNQugCV"; 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 47SkkB0ydfz9sR1 for ; Thu, 5 Dec 2019 03:26:09 +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=T9IPmJ/lQmRSpAOS /wOT1nNIyr4zorAOljmnl+1PH3RgoJOmND+CqeekQtr6GtxMr7b24pBC0tKqhtDU C3A8Oq1Dj9MVGxbDWh3eoNueyk/i+8THjz9m9ofkCDjTgVZSF3RnBBAvwr/qgIji +9ZP2e5EZgfJX2Nwo1es24DBi68= 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=csI3pkbUhLMOTQMJGhxkPu IiFWM=; b=gpa0JzIWQyQcau+jUi7LYjVvgVPiKz7u5PoipVf2suNZYU/PQmmNsT ICUHD776kQXauWVn1K/LH1AUQZYvYRZVNAXR84wWCj+VO2ZMEBZ7UDU17G00BkKV z7gRbx/bZzbMNRFjJZnIT3GQPX7KyVTg9gLYYahfAstw3BUmvSKKI= Received: (qmail 63924 invoked by alias); 4 Dec 2019 16:25:40 -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 63724 invoked by uid 89); 4 Dec 2019 16:25:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=handlers, transitions 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, 04 Dec 2019 16:25:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575476735; 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=uh/DMBcnTdBNY3cwv10hRbIxi8fmtKGA46Q+iX1fEI0=; b=NzNQugCV21u55KPbZPHA+piHZh/2C/Rnl/VCLISc4iVHghjq4lmwTf/DGd4Wngj+X1dxHW YkJu984sWGoLchZHpw35nTH2N4PH3FeN9bvWTV4mNexmq97ZS5czf1Mgp1qdD51Moo1cTu JpVQ5gnFaguT6L2yC60PgzVkZRNCQ+w= 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-313-T0WqSks_Ogysa8CedKe-6A-1; Wed, 04 Dec 2019 11:25:33 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E14D3DBE8 for ; Wed, 4 Dec 2019 16:25:32 +0000 (UTC) Received: from t470.redhat.com (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FB0B5D6AE; Wed, 4 Dec 2019 16:25:32 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 0/7] [analyzer] Add checking for unsafe calls within signal handlers Date: Wed, 4 Dec 2019 11:25:23 -0500 Message-Id: <20191204162530.9285-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-IsSubscribed: yes This patch kit adds a new warning: -Wanalyzer-unsafe-call-within-signal-handler to the analyzer branch. A colorized example of the output can be seen here: https://dmalcolm.fedorapeople.org/gcc/2019-12-04/signal.c.html Currently it only detects calls to "fprintf". This is a new feature beyond what I posted before the stage 1 deadline - but what I posted already contained a couple of proof-of-concept checkers. For now I'm pushing it to the branch, since that seems better than having it just on my hard drive; the supporting patches also contain generalizations of the code that I think are likely to be useful for future work (e.g. supporting C++ exceptions). Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to branch "dmalcolm/analyzer" on the GCC git mirror. Dave David Malcolm (7): [analyzer] Support paths for callbacks [analyzer] More test coverage [analyzer] Generalize rewind_info_t to exploded_edge::custom_info_t [analyzer] Support global states and custom transitions [analyzer] Support custom events [analyzer] Expose state_change_event in evdesc::state_change [analyzer] Add -Wanalyzer-unsafe-call-within-signal-handler gcc/analyzer/Make-plugin.in | 1 + gcc/analyzer/analyzer.h | 2 + gcc/analyzer/checker-path.cc | 62 +++- gcc/analyzer/checker-path.h | 40 ++- gcc/analyzer/diagnostic-manager.cc | 135 +++++--- gcc/analyzer/engine.cc | 143 ++++++-- gcc/analyzer/exploded-graph.h | 85 +++-- gcc/analyzer/pending-diagnostic.h | 8 +- gcc/analyzer/plugin.opt | 4 + gcc/analyzer/program-state.cc | 38 ++- gcc/analyzer/program-state.h | 11 + gcc/analyzer/sm-signal.cc | 304 ++++++++++++++++++ gcc/analyzer/sm.cc | 1 + gcc/analyzer/sm.h | 24 ++ gcc/doc/invoke.texi | 13 + gcc/testsuite/gcc.dg/analyzer/data-model-1.c | 6 + gcc/testsuite/gcc.dg/analyzer/signal-1.c | 31 ++ gcc/testsuite/gcc.dg/analyzer/signal-2.c | 34 ++ gcc/testsuite/gcc.dg/analyzer/signal-3.c | 23 ++ gcc/testsuite/gcc.dg/analyzer/signal-4a.c | 74 +++++ gcc/testsuite/gcc.dg/analyzer/signal-4b.c | 89 +++++ .../gcc.dg/plugin/diagnostic-test-paths-4.c | 83 +++++ .../plugin/diagnostic_plugin_test_paths.c | 81 +++++ gcc/testsuite/gcc.dg/plugin/plugin.exp | 1 + gcc/tree-diagnostic-path.cc | 75 +++-- 25 files changed, 1201 insertions(+), 167 deletions(-) create mode 100644 gcc/analyzer/sm-signal.cc create mode 100644 gcc/testsuite/gcc.dg/analyzer/signal-1.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/signal-2.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/signal-3.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/signal-4a.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/signal-4b.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-test-paths-4.c