From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by sourceware.org (Postfix) with ESMTPS id 0D2F3389042D for ; Mon, 14 Jun 2021 15:19:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D2F3389042D Received: by mail-oo1-xc35.google.com with SMTP id y18-20020a4ae7120000b02902496b7708cfso2724794oou.9 for ; Mon, 14 Jun 2021 08:19:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=j+PekY0umPlr6NP2XEWJXPI3HYe8YqmmgpkluLHle6o=; b=TztpqfQYzkTgCIkMqZvQBbrT9VVwXYYdjr/a9DZZ7p35GOlcoefS2ceOZ00lGkG+ZZ Gn/SA3SMkF0nh4kLdDKxiXlFS0dWqs4ux4cDOgn2zsEOMEepzKKXfyYRZrZqStn9Kn/a ZxxmJymZVEu+vwVDUKoZIL9KwaMW3XaIY6W8XyUouqngDZgto5baJA42ihhjfALh5YoQ z505qOak/QzxqPDYwrYUlfLYdbsqaRMoopoyF5qZeN+rJeBtTyelX6D/khJe+A/kBKfr zVA4fAmI476xq08owdL337Z3kZb+JRFA31q9aILrHOLOziMkZBFMfyErb+hTUk/heP4i ibdw== X-Gm-Message-State: AOAM530dDXxi0v57cchghrJofXu6TjSC0bIIFMZWcL5KKPuC7HyH1YC4 nYhCi3rm8gBVghpQOuwRZNENFDd9/yw= X-Google-Smtp-Source: ABdhPJzqQd1q1DHaNfuj+KBJ60GSDoNcHPN2U6+jgtZPnGvpHFE4hskOYoZC5+rTBTJ9WPH9h31Y/w== X-Received: by 2002:a4a:df47:: with SMTP id j7mr8332731oou.79.1623683950246; Mon, 14 Jun 2021 08:19:10 -0700 (PDT) Received: from [192.168.0.41] (184-96-238-78.hlrn.qwest.net. [184.96.238.78]) by smtp.gmail.com with ESMTPSA id w69sm3008459oia.22.2021.06.14.08.19.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Jun 2021 08:19:09 -0700 (PDT) Subject: Re: gcc warn when pointers not checked non-null before de-referencing. To: Jonny Grant , gcc-help References: <0a9ccbb7-135a-b342-e5cb-35b7c6a44a00@jguk.org> From: Martin Sebor Message-ID: Date: Mon, 14 Jun 2021 09:19:09 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <0a9ccbb7-135a-b342-e5cb-35b7c6a44a00@jguk.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, 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-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jun 2021 15:19:12 -0000 On 6/13/21 4:30 PM, Jonny Grant wrote: > Hello > > This isn't real code, just an example to show. > > I've tried with: -Wall -Wextra -O2 and some other warnings, but couldn't get this to generate a warning that *g was possibly de-referenced. May I ask, does GCC have a way to get warnings when pointers are not checked? > I had a look but -Wnull-dereference didn't help. The pointer test is eliminated before -Wnull-dereference runs so it can't do anything in this case. -fno-delete-null-pointer-checks disables the optimization and retains the test so -Wnull-dereference could in theory detect it but it isn't designed to do it. But if it did, I suspect it would be quite noisy as a result of other transformations like inlining and constant propagation. So making it work with an acceptable S/R ratio would take more work than just enhancing -Wnull-dereference. Martin > > #include > > #include > void f(int * g) > { > *g = 1; > > if(NULL == g) > { > exit(1); > } > } > > Best regards Jonny >