From patchwork Mon Feb 17 07:25:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1239003 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-519619-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.a=rsa-sha1 header.s=default header.b=L04EpxWx; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W8BCtjmG; 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 48LbBB4Mvjz9sPk for ; Mon, 17 Feb 2020 18:25:54 +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=mjtVxQ9+dwd7ZKi4 nr2cGMkQ0q8CFBB3TMZnOzeTD2Idus5XQL9kCDhRuF/9oqphRduiA6NcR/Zg0p6C kfmYZqSVtTZQ8tTB/AhzAtzC6YdmwmsNzf8VMbvcjU76nG62cPofETZDmm4OLL+3 XML3B9pxIC3vobhO3rzmqU+F0TM= 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=METJ070l90KHWsuxFxwfhN jr6Lg=; b=L04EpxWx91l/PEtjbM5ngcvqUCu7XODYXsHs9I36vS+T/GvBfe8RqO GVLK0kSEIZ84AIk70xl2M9fx+L/QOWbUGB/FZDC2pAIEwcsPNZ5+MRt/54cmVCBE /14+MJewdVnrma8SUCsgMwY/dBtY6/x9wfqcuGotUJmGFnxOfRg1c= Received: (qmail 123335 invoked by alias); 17 Feb 2020 07:25:47 -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 123324 invoked by uid 89); 17 Feb 2020 07:25:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=1-2 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; Mon, 17 Feb 2020 07:25:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581924344; 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=RM1VPy/vrXB2Q4j8pk0uQ6NnPlFT85+MYCFR00qEGlo=; b=W8BCtjmGkvfMt2EzEuGlfF8hhmlBu10/ZeSC5TCdz0noB7BzY4Lwg2EPBVEKqpRHF2Rhe+ zYoTACuWWP2QKpNilw7pL3Bi3Yczm0IzywgFhBwEe1WslivAVhGVpoHNC/mM68KCZCdgAz 3DWXcJZcFkIN7/D0wYwfGTew7YuyrLw= 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-406-RfrqpO1uOeKfGegBk_1Zbg-1; Mon, 17 Feb 2020 02:25:39 -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 68172800D53 for ; Mon, 17 Feb 2020 07:25:38 +0000 (UTC) Received: from t470.redhat.com (ovpn-116-56.phx2.redhat.com [10.3.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id F07255C10D; Mon, 17 Feb 2020 07:25:37 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: fix wording for assignment from NULL Date: Mon, 17 Feb 2020 02:25:36 -0500 Message-Id: <20200217072536.25689-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes This patch improves the wording of the state-transition event (1) in the -Wanalyzer-null-dereference diagnostic for: void test (void) { int *p = NULL; *p = 1; } taking the path description from: ‘test’: events 1-2 | | 5 | int *p = NULL; | | ^ | | | | | (1) assuming ‘p’ is NULL | 6 | *p = 1; | | ~~~~~~ | | | | | (2) dereference of NULL ‘p’ | to: ‘test’: events 1-2 | | 5 | int *p = NULL; | | ^ | | | | | (1) ‘p’ is NULL | 6 | *p = 1; | | ~~~~~~ | | | | | (2) dereference of NULL ‘p’ | since the "assuming" at (1) only makes sense for state transitions due to comparisons, not for assignments. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to master as 0993ad65cc4e462223e9337d9b2d3b82a887c6c8. gcc/analyzer/ChangeLog: * sm-malloc.cc (malloc_diagnostic::describe_state_change): For transition to the "null" state, only say "assuming" when transitioning from the "unchecked" state. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/malloc-1.c (test_48): New. --- gcc/analyzer/sm-malloc.cc | 11 +++++++++-- gcc/testsuite/gcc.dg/analyzer/malloc-1.c | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index bdd0731b5d1..46225b6f700 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -130,8 +130,15 @@ public: return change.formatted_print ("assuming %qE is non-NULL", change.m_expr); if (change.m_new_state == m_sm.m_null) - return change.formatted_print ("assuming %qE is NULL", - change.m_expr); + { + if (change.m_old_state == m_sm.m_unchecked) + return change.formatted_print ("assuming %qE is NULL", + change.m_expr); + else + return change.formatted_print ("%qE is NULL", + change.m_expr); + } + return label_text (); } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c index c13170560af..3024e546137 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c @@ -583,3 +583,9 @@ int test_47 (void) } return p_size; } + +void test_48 (void) +{ + int *p = NULL; /* { dg-message "'p' is NULL" } */ + *p = 1; /* { dg-warning "dereference of NULL 'p'" } */ +}