From patchwork Mon Feb 1 00:31:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1433989 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=MAVSE8ly; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DTTQB0n5hz9t1D for ; Mon, 1 Feb 2021 11:31:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C23D384A02C; Mon, 1 Feb 2021 00:31:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C23D384A02C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1612139470; bh=2CIkGrlqPDH5A2GvIZCTBReDLtXCO1XbaJMzCEF5wS8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=MAVSE8ly+MsM62Ldz/zWFbxJlPsvxKHwfAWDpRDDEIZb4r7Xie3lon2nQnCi0dxFQ AFwmshrMKVMF/qpR4ez4XU1TdwyCGu98wmyw5FxFldGfqdOweLKgDcb1PiR7FYyNhy RqJziUDji0lXCIG/66wkxb+JRHBM3NNGa6nXmhpk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id A8ECF384B406 for ; Mon, 1 Feb 2021 00:31:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A8ECF384B406 Received: by mail-qt1-x835.google.com with SMTP id t17so11138846qtq.2 for ; Sun, 31 Jan 2021 16:31:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=2CIkGrlqPDH5A2GvIZCTBReDLtXCO1XbaJMzCEF5wS8=; b=i3szKZ/z20YKV5rNEFbXmjIsO3PB1XDk8pHQikVXQcjXRqPPRa8Fmwgwi6hatP7tFP ySufIKlbzw+1s/6f7N+XRO8WMOoRimChBg7aHJINQuCfRTg4jF++tR+kN0zQed3E/5Vz 1C4Az2TNCZUJbVxCvTYIpQ2Ve4m+JJc9YHVIv6TQ7OANNqWLpnymeXbtgfhpKXfFqzlU bVNsrtwSpZtnGCpO4JmXF8T8dhoIL3oEoUn+MepyAS7lSYE/AsVBeueuzx1cxox4sBWz h+SvS/57vILZGFpb8A/pPc5rew50zu75iT8mAOx2+PSScXi1DcBqHzPV4WHG1PO1ePvu kFlg== X-Gm-Message-State: AOAM532tZ0aSAN3Xowx5yA3FVhrxgn4a+Pou5GDGghK6kNJmPLsd3Hix BVyKgFpasTckjOqkoQbtXueqP/aWFWE= X-Google-Smtp-Source: ABdhPJxYR+cr1kq+wgPsXlBmxFu8fPy83DOfGGWBFQsJANjsKqhl1e1R0/y2kBuCtleTHw212iD68w== X-Received: by 2002:a05:622a:3ca:: with SMTP id k10mr13520718qtx.270.1612139467146; Sun, 31 Jan 2021 16:31:07 -0800 (PST) Received: from [192.168.0.41] (184-96-239-30.hlrn.qwest.net. [184.96.239.30]) by smtp.gmail.com with ESMTPSA id c15sm12332365qkj.129.2021.01.31.16.31.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 31 Jan 2021 16:31:06 -0800 (PST) To: gcc-patches Subject: [PATCH] run -Wnonnull later (PR 87489) Message-ID: <1f4b76ee-067f-bb5e-1ed1-39286c5f7c75@gmail.com> Date: Sun, 31 Jan 2021 17:31:04 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The initial -Wnonnull implementation in the middle end took place too late in the pipeline (just before expansion), and as a result was prone to false positives (bug 78817). In an attempt to avoid the worst of those, the warning was moved to the ccp2 pass in r243874. However, as the test case in PR 87489 shows, this is in turn too early and causes other false positives as a result. A few experiments with running the warning later suggest that just before the mergephi2 pass is a good point to avoid this class of false positives without causing any regressions or introducing any new warnings either in Glibc or in Binutils/GDB. Since PR 87489 is a GCC 8-11 regression I propose to make this change on the trunk as well as on the release branches. Martin PR middle-end/87489 - Spurious -Wnonnull warning on bitwise arithmetic and inlining gcc/ChangeLog: PR middle-end/87489 * passes.def (pass_post_ipa_warn): Move later. gcc/testsuite/ChangeLog: PR middle-end/87489 * gcc.dg/Wnonnull-6.c: New test. * gcc.dg/Wnonnull-7.c: New test. diff --git a/gcc/passes.def b/gcc/passes.def index e9ed3c7bc57..5e5a012943a 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -194,7 +194,6 @@ along with GCC; see the file COPYING3. If not see They ensure memory accesses are not indirect wherever possible. */ NEXT_PASS (pass_strip_predict_hints, false /* early_p */); NEXT_PASS (pass_ccp, true /* nonzero_p */); - NEXT_PASS (pass_post_ipa_warn); /* After CCP we rewrite no longer addressed locals into SSA form if possible. */ NEXT_PASS (pass_complete_unrolli); @@ -207,6 +206,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_build_alias); NEXT_PASS (pass_return_slot); NEXT_PASS (pass_fre, true /* may_iterate */); + NEXT_PASS (pass_post_ipa_warn); NEXT_PASS (pass_merge_phi); NEXT_PASS (pass_thread_jumps); NEXT_PASS (pass_vrp, true /* warn_array_bounds_p */); @@ -368,7 +368,6 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_lower_switch); /* Perform simple scalar cleanup which is constant/copy propagation. */ NEXT_PASS (pass_ccp, true /* nonzero_p */); - NEXT_PASS (pass_post_ipa_warn); NEXT_PASS (pass_object_sizes); /* Fold remaining builtins. */ NEXT_PASS (pass_fold_builtins); @@ -377,6 +376,7 @@ along with GCC; see the file COPYING3. If not see to forward object-size and builtin folding results properly. */ NEXT_PASS (pass_copy_prop); NEXT_PASS (pass_dce); + NEXT_PASS (pass_post_ipa_warn); NEXT_PASS (pass_sancov); NEXT_PASS (pass_asan); NEXT_PASS (pass_tsan); diff --git a/gcc/testsuite/gcc.dg/Wnonnull-6.c b/gcc/testsuite/gcc.dg/Wnonnull-6.c new file mode 100644 index 00000000000..507e7979cd0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wnonnull-6.c @@ -0,0 +1,25 @@ +/* PR middle-end/87489 - Spurious -Wnonnull warning on bitwise arithmetic + and inlining + { dg-do compile } + { dg-options "-O1 -Wall" } */ + +extern void f (const void*, int); + +static void g (int i, const char *s) +{ + int j = 0; + + if (i) + j |= 1; + + if (j) + f (&j, 0); + + if (j & 1) + f (s, __builtin_strlen (s)); // { dg-bogus "\\\[-Wnonnull" } +} + +void h (void) +{ + g (0, 0); +} diff --git a/gcc/testsuite/gcc.dg/Wnonnull-7.c b/gcc/testsuite/gcc.dg/Wnonnull-7.c new file mode 100644 index 00000000000..d801ca2329d --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wnonnull-7.c @@ -0,0 +1,6 @@ +/* PR middle-end/87489 - Spurious -Wnonnull warning on bitwise arithmetic + and inlining + { dg-do compile } + { dg-options "-Og -Wall" } */ + +#include "Wnonnull-6.c"