[Bug c/91554] if (!__builtin_constant_p (x)) warning_function() works in inline when x is int, not when x is void *

2019-08-27 Thread zackw at panix dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91554

--- Comment #2 from Zack Weinberg  ---
Additional fun detail:

```
static inline int
thefun (void *a, void *b)
{
   if (!__builtin_constant_p((__UINTPTR_TYPE__)b) || b != 0)
   thefun_called_with_nonnull_arg();
   return real_thefun(a, b);
}
```

still warns for any use of `thefun`, but

```
static inline int
thefun (void *a, void *b)
{
   if (!__builtin_constant_p((short)(__UINTPTR_TYPE__)b) || b != 0)
   thefun_called_with_nonnull_arg();
   return real_thefun(a, b);
}
```

works as intended!  `(int)(__UINTPTR_TYPE__)` also works as intended on targets
where __UINTPTR_TYPE__ is bigger than int.

https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/builtins.c;h=f902e246f1f347be4d4dc04e339fa865393039fe#l8462
looks suspicious to me.  Note also the STRIP_NOPS shortly above, which might
explain why it matters whether the pointer is cast to a different-sized integer
type.

[Bug c/91554] if (!__builtin_constant_p (x)) warning_function() works in inline when x is int, not when x is void *

2019-08-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91554

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-08-27
Version|unknown |9.2.1
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
Already the frontend (or GENERIC expression simplification) generates

;; Function thefun (null)
;; enabled by -tree-original


{
  if (1)
{
  thefun_called_with_nonnull_arg ();
}
  return real_thefun (a, b);

I couldn't quickly spot who does this though...