public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, PR 67133] Always change gimple fntype in cgraph_edge::redirect_call_stmt_to_callee
@ 2015-08-17 13:46 Martin Jambor
  2015-08-17 13:53 ` Jan Hubicka
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Jambor @ 2015-08-17 13:46 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jan Hubicka

Hi,

even though PR 67133 has been avoided by a different patch, I believe
the patch below is the correct fix.  It modifies the function that
changes call statements according to call graph edges so that it
changes the fntype of the call statements also when
combined_args_to_skip is NULL.  This code path is taken for example
when a call is redirected to __builtin_unreachable and then the type
of the callee function is likely to mismatch with fntype of the
statement, which can confuse the compiler later on.

If we agree it is a good idea, I'd like to also propose a patch
making the gimple verifier check whether fntypes of direct call
statements match the types of the callee (or at least that they have
the same number of same-typed arguments).

The patch has been bootstrapped and tested on x86_64-linux, the
testcase is already checked in.  OK for trunk?

Thanks,

Martin


2015-08-17  Martin Jambor  <mjambor@suse.cz>

	PR middle-end/67133
	* cgraph.c (redirect_call_stmt_to_callee): Set gimple call fntype also
	when redirecting without removing any parameters.

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 22a9852..5e5b308 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -1461,6 +1461,7 @@ cgraph_edge::redirect_call_stmt_to_callee (void)
     {
       new_stmt = e->call_stmt;
       gimple_call_set_fndecl (new_stmt, e->callee->decl);
+      gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
       update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
     }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, PR 67133] Always change gimple fntype in cgraph_edge::redirect_call_stmt_to_callee
  2015-08-17 13:46 [PATCH, PR 67133] Always change gimple fntype in cgraph_edge::redirect_call_stmt_to_callee Martin Jambor
@ 2015-08-17 13:53 ` Jan Hubicka
  2015-08-17 14:13   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Hubicka @ 2015-08-17 13:53 UTC (permalink / raw)
  To: GCC Patches, Jan Hubicka

> Hi,
> 
> even though PR 67133 has been avoided by a different patch, I believe
> the patch below is the correct fix.  It modifies the function that
> changes call statements according to call graph edges so that it
> changes the fntype of the call statements also when
> combined_args_to_skip is NULL.  This code path is taken for example
> when a call is redirected to __builtin_unreachable and then the type
> of the callee function is likely to mismatch with fntype of the
> statement, which can confuse the compiler later on.
> 
> If we agree it is a good idea, I'd like to also propose a patch
> making the gimple verifier check whether fntypes of direct call
> statements match the types of the callee (or at least that they have
> the same number of same-typed arguments).
> 
> The patch has been bootstrapped and tested on x86_64-linux, the
> testcase is already checked in.  OK for trunk?
> 
> Thanks,
> 
> Martin
> 
> 
> 2015-08-17  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR middle-end/67133
> 	* cgraph.c (redirect_call_stmt_to_callee): Set gimple call fntype also
> 	when redirecting without removing any parameters.

This makes sense in the case of __builtin_unreachable.  I wonder if we have
some problems in cases where LTO or indirect call code places in incompatible
declaration.

Patch is fine with me, but I would like Richi to have final word on this one.

Honza
> 
> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
> index 22a9852..5e5b308 100644
> --- a/gcc/cgraph.c
> +++ b/gcc/cgraph.c
> @@ -1461,6 +1461,7 @@ cgraph_edge::redirect_call_stmt_to_callee (void)
>      {
>        new_stmt = e->call_stmt;
>        gimple_call_set_fndecl (new_stmt, e->callee->decl);
> +      gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
>        update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
>      }
>  

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, PR 67133] Always change gimple fntype in cgraph_edge::redirect_call_stmt_to_callee
  2015-08-17 13:53 ` Jan Hubicka
@ 2015-08-17 14:13   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2015-08-17 14:13 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

On Mon, Aug 17, 2015 at 3:47 PM, Jan Hubicka <hubicka@ucw.cz> wrote:
>> Hi,
>>
>> even though PR 67133 has been avoided by a different patch, I believe
>> the patch below is the correct fix.  It modifies the function that
>> changes call statements according to call graph edges so that it
>> changes the fntype of the call statements also when
>> combined_args_to_skip is NULL.  This code path is taken for example
>> when a call is redirected to __builtin_unreachable and then the type
>> of the callee function is likely to mismatch with fntype of the
>> statement, which can confuse the compiler later on.
>>
>> If we agree it is a good idea, I'd like to also propose a patch
>> making the gimple verifier check whether fntypes of direct call
>> statements match the types of the callee (or at least that they have
>> the same number of same-typed arguments).
>>
>> The patch has been bootstrapped and tested on x86_64-linux, the
>> testcase is already checked in.  OK for trunk?
>>
>> Thanks,
>>
>> Martin
>>
>>
>> 2015-08-17  Martin Jambor  <mjambor@suse.cz>
>>
>>       PR middle-end/67133
>>       * cgraph.c (redirect_call_stmt_to_callee): Set gimple call fntype also
>>       when redirecting without removing any parameters.
>
> This makes sense in the case of __builtin_unreachable.  I wonder if we have
> some problems in cases where LTO or indirect call code places in incompatible
> declaration.
>
> Patch is fine with me, but I would like Richi to have final word on this one.

I don't like it too much - you'll scribble over users ABI choice here.
It's better
to guard inspectors of the call properly to _not_ expect actual arguments
according to the ABI.

Richard.

> Honza
>>
>> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
>> index 22a9852..5e5b308 100644
>> --- a/gcc/cgraph.c
>> +++ b/gcc/cgraph.c
>> @@ -1461,6 +1461,7 @@ cgraph_edge::redirect_call_stmt_to_callee (void)
>>      {
>>        new_stmt = e->call_stmt;
>>        gimple_call_set_fndecl (new_stmt, e->callee->decl);
>> +      gimple_call_set_fntype (new_stmt, TREE_TYPE (e->callee->decl));
>>        update_stmt_fn (DECL_STRUCT_FUNCTION (e->caller->decl), new_stmt);
>>      }
>>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-17 14:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-17 13:46 [PATCH, PR 67133] Always change gimple fntype in cgraph_edge::redirect_call_stmt_to_callee Martin Jambor
2015-08-17 13:53 ` Jan Hubicka
2015-08-17 14:13   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).