This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] tighten up -Wbuiltin-declaration-mismatch (PR 86125)


On Thu, Jun 14, 2018 at 12:35 AM Martin Sebor <msebor@gmail.com> wrote:
>
> The C implementation of the -Wbuiltin-declaration-mismatch
> warning relies on TYPE_MODE to detect incompatibilities
> between return and argument types in user declarations of
> built-in functions.  That prevents mistakes like
>
>    char* strlen (const char*);
>
> from being detected (where sizeof (char*) == sizeof (size_t)),
> while at the same diagnosing similar bugs such as
>
>    char* strcmp (const char*, const char*);
>
> where sizeof (char*) != sizeof (int), and always diagnosing
> benign declarations like:
>
>    void strcpy (char*, const char*)
>
> The attached patch tightens up the detection of incompatible
> types so that when -Wextra is set it diagnoses more of these
> kinds of problems, including mismatches in qualifiers.  (I
> added this under -Wextra mainly to avoid the warning with
> just -Wall for some of the more benign incompatibilities
> like those in const-qualifiers).
>
> This enhancement was prompted by bug 86114.  As it is, it
> would not have prevented the ICE in that bug because it does
> not reject the incompatible redeclaration (I did that to keep
> compatibility with prior GCC versions).  If there is support
> for it, though, I think rejecting all incompatible declarations
> would be a better solution.  Partly because the middle-end
> doesn't seem to fully consider incompatible return types and
> so might end up introducing transformations that don't make
> sense.  And partly because I think at least the C and POSIX
> standard built-in functions should be declared with
> the types they are specified.

Why not go the simpler way of doing

  || POINTER_TYPE_P (oldrettype) != POINTER_TYPE_P (newrettype)

after the mode check?  I don't think a mismatch in pointer vs.
non-pointer was a desired loophole.

Richard.

> Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]