[Bug middle-end/68767] spurious warning: null argument where non-null required

2015-12-08 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68767

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek  ---
Reduced:

extern int len (const char *__s) __attribute__ ((__nonnull__ (1)));
extern int num;

int
f (void)
{
  return len (num != 2 ? "a" : 0);
}

Looks like it's been like this forever.  We're hitting:
 9752   if (TREE_CODE (param) == COND_EXPR)
 9753 {
 9754   tree cond = fold_for_warn (TREE_OPERAND (param, 0));
 9755   /* Check both halves of the conditional expression.  */
 9756   if (!integer_zerop (cond))
 9757 check_function_arguments_recurse (callback, ctx,
 9758   TREE_OPERAND (param, 1),
param_num);
 9759   if (!integer_nonzerop (cond))
 9760 check_function_arguments_recurse (callback, ctx,
 9761   TREE_OPERAND (param, 2),
param_num);
 9762   return;
 9763 }

[Bug middle-end/68767] spurious warning: null argument where non-null required

2015-12-09 Thread manu at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68767

Manuel López-Ibáñez  changed:

   What|Removed |Added

 CC||manu at gcc dot gnu.org

--- Comment #2 from Manuel López-Ibáñez  ---
I don't understand. It is indeed passing NULL to a non-null function. What is
wrong with the warning?

[Bug middle-end/68767] spurious warning: null argument where non-null required

2015-12-09 Thread amylaar at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68767

--- Comment #3 from Jorn Wolfgang Rennecke  ---
(In reply to Manuel López-Ibáñez from comment #2)
> I don't understand. It is indeed passing NULL to a non-null function. What
> is wrong with the warning?

When you look at the original testcase closely, you'll see that it can never
(unless there is a race condition, invoking undefined behaviour) pass NULL.
In fact, it always passes "lstr" .

The the reduced testcase from comment #1 is more ambiguous.  If it can or can
not pass NULL depends on values that the variable might attain.