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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
But in that case the POINTER_TYPE_P case doesn't trigger, because it is
INTEGER_CST and
so
  /* If we know this is a constant, emit the constant of one.  */
  if (CONSTANT_CLASS_P (arg)
      || (TREE_CODE (arg) == CONSTRUCTOR
          && TREE_CONSTANT (arg)))
    return integer_one_node;
triggers first.
There is another case where the builtin can return true for a pointer, and that
is
when it is called with a string literal (__builtin_constant_p ("abcd")):
  if (TREE_CODE (arg) == ADDR_EXPR)
    {
       tree op = TREE_OPERAND (arg, 0);           
       if (TREE_CODE (op) == STRING_CST
           || (TREE_CODE (op) == ARRAY_REF
               && integer_zerop (TREE_OPERAND (op, 1))
               && TREE_CODE (TREE_OPERAND (op, 0)) == STRING_CST))
         return integer_one_node;
    }
But if you use even in the same function
  int volatile *psfr = SFR;
  __builtin_constant_p (psfr)
it will fold to 0.

Reply via email to