https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91554

--- Comment #4 from Zack Weinberg <zackw at panix dot com> ---
(In reply to Richard Biener from comment #3)
> I guess you want to use
> 
> __builtin_constant_p (b != 0)
> 
> instead.

That wouldn't do what I want.  The goal is to warn for any argument _other
than_ a compile-time null pointer.  `!__builtin_constant_p(b) || b != 0` does
just that (it might be easier to understand the De Morgan equivalent
`!(__builtin_constant_p(b) && b == 0)`.  This is in aid of deprecating the
second argument to gettimeofday (see
https://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS;h=75453bbda865c7d51df39177caef40b16e086dcf#l53
and
https://sourceware.org/git/?p=glibc.git;a=blob;f=manual/time.texi;h=cb234bd08fae1841034a2bdccf4e1d246be23034#l557
).

> The docs don't explain what a "constant at compile time" is
> so whether for example the address of a global or the address of an
> automatic var would be "constant".  But I'd say the above incorrectly
> disregards the NULL-pointer case.

It seems like this code pre-dates tree optimizations, I would suggest removing
these lines

8470       || AGGREGATE_TYPE_P (TREE_TYPE (arg))
8471       || POINTER_TYPE_P (TREE_TYPE (arg))

(and fixing the comment above to match) and seeing if that breaks anything.

Reply via email to