This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH to fix -Wrestrict ICE (PR middle-end/83463)
- From: Martin Sebor <msebor at gmail dot com>
- To: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- Cc: Jakub Jelinek <jakub at redhat dot com>, Marek Polacek <polacek at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 18 Dec 2017 11:51:58 -0700
- Subject: Re: PATCH to fix -Wrestrict ICE (PR middle-end/83463)
- Authentication-results: sourceware.org; auth=none
- References: <AM5PR0701MB26572B793CBEFED21D9162EFE40E0@AM5PR0701MB2657.eurprd07.prod.outlook.com>
On 12/18/2017 11:32 AM, Bernd Edlinger wrote:
Hi Martin,
In all cases all the information necessary to detect and diagnose
or even avoid the problem is available. In fact, one might argue
that optimizing such calls (expanding them inline) would be
preferable to doing nothing and allowing the undefined behavior
to cause a bug at runtime.
I think the right thing to do here would emit a warning for
declaring the builtin with the wrong prototype.
If you try to do the equivalent in C++ you get this:
cat test.cc
extern "C" void* memcpy (...);
void p (void *d, const void *s)
{
memcpy (d, s, 0);
}
g++ -S test.cc
test.cc:1:18: warning: declaration of ‘void* memcpy(...)’ conflicts with built-in declaration ‘void* memcpy(void*, const void*, long unsigned int)’ [-Wbuiltin-declaration-mismatch]
extern "C" void* memcpy (...);
^~~~~~
You get the same warning in C when the Prototype does not match,
but unfortunately not when the prototype is missing.
I would prefer the same warning in C whenever the declaration does
not match.
That sounds good to me.
I do think that, in addition, issuing another warning for calls
with arguments of the wrong type (or wrong number) would be useful
as well, or in fact even more so. It will make it possible to
distinguish safe calls to such functions from unsafe ones. These
two could be part of the same enhancement or independent of one
another.
Martin