This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCHv3] Add a warning for invalid function casts
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, Jeff Law <law at redhat dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Thu, 14 Dec 2017 18:35:40 +0000
- Subject: Re: [PATCHv3] Add a warning for invalid function casts
- Authentication-results: sourceware.org; auth=none
- References: <AM5PR0701MB265700BCFDF7620223717DCCE4720@AM5PR0701MB2657.eurprd07.prod.outlook.com> <87146b27-e57b-0f0d-bd14-53a2c2acd67c@redhat.com> <40891950-f967-1ce6-3cc9-8595cde9a133@hotmail.de> <CADzB+2mvudrJ5rp5_GujKTL5UjySjD2B_pEpW=+0m8D9ypjr4g@mail.gmail.com> <AM5PR0701MB265795768D78BACF3C350376E4380@AM5PR0701MB2657.eurprd07.prod.outlook.com> <CADzB+2=__g1yojLZHc47inaugoO4zCKRw_f6PmmOs_ELM7am-A@mail.gmail.com> <AM5PR0701MB2657C441A17E36768453C466E4380@AM5PR0701MB2657.eurprd07.prod.outlook.com> <CADzB+2=bt8SSu=pHn6d3r=aFCJKV4mmc9D3RmYJ=1VzjLWmJng@mail.gmail.com> <AM5PR0701MB2657479575BEA81366552BD3E4380@AM5PR0701MB2657.eurprd07.prod.outlook.com> <CADzB+2kQx6ExiO7bGf6UhWEC8wLZHB+3bpkc16n5=BDDzE4DTg@mail.gmail.com> <AM5PR0701MB26573F24B606519E3CA56997E4390@AM5PR0701MB2657.eurprd07.prod.outlook.com> <CADzB+2miocvzJxg1v9iD7MoT=GvRa7o_8ZQoe8HkZDtd0i3OWw@mail.gmail.com> <1c3d1b9b-7a25-fae3-5c44-1a0efae77cc8@hotmail.de>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On 12/07/17 21:48, Bernd Edlinger wrote:
> On 12/06/17 23:35, Jason Merrill wrote:
>> On Fri, Dec 1, 2017 at 7:42 AM, Bernd Edlinger
>> <bernd.edlinger@hotmail.de> wrote:
>>> this version of the patch improves the heuristic check to take the
>>> target hook into account, to handle cases correctly when both or only
>>> one parameter is _not_ promoted to int.
>>
>> In looking at this, I discovered that the argument to
>> promote_prototypes should be the function type, not the parameter
>> type; the existing uses in the C++ front end were wrong.
>>
>
> Bah, sorry.
>
> Yes, it looks like there are at least two more target hooks that change
> the type promotion rules later-on: targetm.calls.promote_function_mode
> and PROMOTE_MODE.
>
> In the ada FE we pass NULL_TREE to promote_prototypes which seems to
> mean if the target wants type promotion in principle. So it returns
> true if some function may promote, and false if no function promotes.
> At least this is how the sh-target handles this parameter.
> This is BTW the only target that uses the argument of this callback.
>
> So I would think for the purpose of this warning the following check
> should be sufficient:
>
> if (INTEGRAL_TYPE_P (t1)
> && INTEGRAL_TYPE_P (t2)
> && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)
> && (TYPE_UNSIGNED (t1) == TYPE_UNSIGNED (t2)
> || !targetm.calls.promote_prototypes (NULL_TREE)
> || TYPE_PRECISION (t1) >= TYPE_PRECISION (integer_type_node)))
>
>
> What do you think?
> Is the patch OK with this change?
>
So, is the simplified heuristic using only promote_prototypes (NULL)
OK?
Thanks
Bernd.