Collin Funk wrote:
> Interesting. Based on the comment above the function that performs this
> optimization, this seems like a bug [1]:
I don't see a bug. The optimization simplifies
fprintf (fp, "%s", value);
to
fputs (value, fp);
This optimization is allowed by the standards. And fputs does not allow
a NULL value.
> Later below, it looks like there is an attempt to check if the argument
> is NULL:
>
> /* If the format specifier was "%s", call __builtin_fputs (arg, fp). */
> else if (strcmp (fmt_str, target_percent_s) == 0)
> {
> if (!arg || ! POINTER_TYPE_P (TREE_TYPE (arg)))
> return false;
1) I don't see such a test. The '! arg' test looks more like a precaution
to avoid a crash in TREE_TYPE (arg).
2) In general, gcc can't tell whether value will be NULL at run time or not.
Bruno