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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
In reply to bug 89566 comment #5, one strategy is to do the same thing that's
already done for built-ins (possibly implicitly) declared with an incompatible
prototype: treat invalid calls as ordinary ones.  For example:

  char a[8];

  void f (void)
  {
    memcpy (a, 8, "01234567");   // library call
  }

  void g (void)
  {
    memcpy (a, "01234567", 8);   // folded to MEM_REF
  }

This is far from ideal since the call will very likely corrupt something or
crash.  The only redeeming argument in favor of it is that GCC has gotten
pretty good at warning for these bugs (but warnings can be suppressed).

Another solution might be to replace these invalid calls with traps.  The
choice between these strategies (or any others) could be controlled by some
option as has been suggested elsewhere for other kinds of undefined behavior
(e.g., pr89561).  The trap solution could obviously only be deployed only for
calls that would result in corruption, like with insufficient or excess
arguments or arguments of ABI-incompatible types, etc.  I think
-Wbad-function-cast already tries to trigger only for these kinds of casts.

Reply via email to