[Bug c/93812] [9/10 Regression] ICE on redeclaration of an attribute format function without protoype

2020-03-01 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93812

Martin Sebor  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #7 from Martin Sebor  ---
Fixed.

[Bug c/93812] [9/10 Regression] ICE on redeclaration of an attribute format function without protoype

2020-03-01 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93812

--- Comment #6 from CVS Commits  ---
The master branch has been updated by Martin Sebor :

https://gcc.gnu.org/g:a499c2f899961f2c09db2dc33e60b66e8d770092

commit r10-6960-ga499c2f899961f2c09db2dc33e60b66e8d770092
Author: Martin Sebor 
Date:   Sun Mar 1 17:41:45 2020 -0700

PR c/93812 - ICE on redeclaration of an attribute format function without
protoype

gcc/c/ChangeLog:

PR c/93812
* c-typeck.c (build_functype_attribute_variant): New function.
(composite_type): Call it.

gcc/testsuite/ChangeLog:

PR c/93812
* gcc.dg/format/proto.c: New test.

[Bug c/93812] [9/10 Regression] ICE on redeclaration of an attribute format function without protoype

2020-02-26 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93812

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #5 from Martin Sebor  ---
Patch: https://gcc.gnu.org/ml/gcc-patches/2020-02/msg01503.html

[Bug c/93812] [9/10 Regression] ICE on redeclaration of an attribute format function without protoype

2020-02-26 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93812

Martin Sebor  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |msebor at gcc dot 
gnu.org
Summary|[9/10 Regression] ICE in|[9/10 Regression] ICE on
   |get_constant, at|redeclaration of an
   |c-family/c-format.c:325 |attribute format function
   ||without protoype

--- Comment #4 from Martin Sebor  ---
I'm not sure it makes sense to accept attribute format on functions without a
prototype.  It certainly doesn't make sense to keep it after a declaration to
which it can't be applied has been seen.  The only other kind of a declaration
that the attribute can meaningfully be applied is a variadic one but such is
not accepted after one without a prototype.

GCC 8 does accept the attribute on functions without a prototype and even seems
to do behave sensibly for "sensible" calls with the format argument in the
right place, but without -Wformat-nonliteral it doesn't do anything useful if
the format argument is not of the right type (e.g., because it's misplaced)
such as in:

  __attribute__((__format__(__printf__, 1, 2))) void foo ();

  void bar (void)
  {
foo (1, "%s", 2);   // no warning
  }

(As an aside, not diagnosing at least the call if not the declaration seems
like a bug because GCC doesn't accept attribute format on variadic functions
where the format doesn't have a declared type compatible with char* and where
the first-to-check argument isn't the position of the ellipsis (i.e., it can't
be an arbitrary position within the variable argument list).)

A simple solution is to simply drop the attribute from functions without a
prototype with a warning like Clang does:

  warning: '__format__' attribute only applies to Objective-C
methods, blocks, and non-K functions [-Wignored-attributes]

A slightly more involved but less intrusive (to user code) solution is to drop
it when a redeclaration is seen with a prototype.