This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH to fix missing warning (PR c++/70194)
- From: Patrick Palka <patrick at parcs dot ath dot cx>
- To: Jeff Law <law at redhat dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, Marek Polacek <polacek at redhat dot com>, Jason Merrill <jason at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 17 Mar 2016 12:48:30 -0400
- Subject: Re: C++ PATCH to fix missing warning (PR c++/70194)
- Authentication-results: sourceware.org; auth=none
- References: <20160315104120 dot GC10006 at redhat dot com> <20160315105618 dot GT3017 at tucnak dot redhat dot com> <20160315120918 dot GD10006 at redhat dot com> <56E86580 dot 70800 at redhat dot com> <20160316144552 dot GG10006 at redhat dot com> <56E9FDBB dot 5070903 at gmail dot com> <56EADB0E dot 3010304 at redhat dot com>
On Thu, Mar 17, 2016 at 12:27 PM, Jeff Law <law@redhat.com> wrote:
> On 03/16/2016 06:43 PM, Martin Sebor wrote:
>>>
>>> @@ -3974,6 +3974,38 @@ build_vec_cmp (tree_code code, tree type,
>>> return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
>>> }
>>>
>>> +/* Possibly warn about an address never being NULL. */
>>> +
>>> +static void
>>> +warn_for_null_address (location_t location, tree op, tsubst_flags_t
>>> complain)
>>> +{
>>
>> ...
>>>
>>> + if (TREE_CODE (cop) == ADDR_EXPR
>>> + && decl_with_nonnull_addr_p (TREE_OPERAND (cop, 0))
>>> + && !TREE_NO_WARNING (cop))
>>> + warning_at (location, OPT_Waddress, "the address of %qD will never "
>>> + "be NULL", TREE_OPERAND (cop, 0));
>>> +
>>> + if (CONVERT_EXPR_P (op)
>>> + && TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == REFERENCE_TYPE)
>>> + {
>>> + tree inner_op = op;
>>> + STRIP_NOPS (inner_op);
>>> +
>>> + if (DECL_P (inner_op))
>>> + warning_at (location, OPT_Waddress,
>>> + "the compiler can assume that the address of "
>>> + "%qD will never be NULL", inner_op);
>>
>>
>> Since I noted the subtle differences between the phrasing of
>> the various -Waddress warnings in the bug, I have to ask: what is
>> the significance of the difference between the two warnings here?
>>
>> Would it not be appropriate to issue the first warning in the latter
>> case? Or perhaps even use the same text as is already used elsewhere:
>> "the address of %qD will always evaluate as âtrueâ" (since it may not
>> be the macro NULL that's mentioned in the expression).
>
> They were added at different times AFAICT. The former is fairly old
> (Douglas Gregor, 2008) at this point. The latter was added by Patrick Palka
> for 65168 about a year ago.
>
> You could directly ask Patrick about motivations for a different message.
There is no plausible way for the address of a non-reference variable
to be NULL even in code with UB (aside from __attribute__ ((weak)) in
which case the warning is suppressed). But the address of a reference
can easily seem to be NULL if one performs UB and assigns to it *(int
*)NULL or something like that. I think that was my motivation, anyway
:)