* [Ada] Fix indirect calls to imported subprograms within generic
@ 2017-12-05 12:23 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2017-12-05 12:23 UTC (permalink / raw)
To: gcc-patches; +Cc: Olivier Hainque
[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]
Our trampoline avoidance scheme based on subprogram descriptors
should always be disconnected for subprograms with foreign convention.
For access to subprogram subtypes, the Set_Convention front-end
procedure is expected to take care of this, but it currently only
does so for subtypes not within a generic instance.
This causes wrong code to be generated on many targets for the
testcase below, where the indirect call from Trigger is performed
through a (non existent) descriptor, resulting in SEGV in most
circumstances.
/* cfoo.c */
void c_foo ()
{
printf ("hello there from C");
}
-- blob.ads
generic
package Blob is
procedure Initialize;
procedure Trigger;
end;
-- blob.adb
package body Blob is
type Service_Ptr is access procedure;
pragma Convention (C, Service_Ptr);
Hook : Service_Ptr;
procedure C_Foo;
pragma Import (C, C_Foo, "c_foo");
procedure Initialize is
begin
Hook := C_Foo'Access;
end;
procedure Trigger is
begin
Hook.all;
end;
end;
The change proposed here just arranges for the bit clearing
to happen systematically in Set_Convention, which fixes the case
at hand and just confirms the bit value in case the entity was
processed previously.
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-12-05 Olivier Hainque <hainque@adacore.com>
* sem_util.adb (Set_Convention): Always clear Can_Use_Internal_Rep
on access to subprogram types with foreign convention.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 840 bytes --]
Index: sem_util.adb
===================================================================
--- sem_util.adb (revision 255412)
+++ sem_util.adb (working copy)
@@ -23090,17 +23090,7 @@
and then Is_Access_Subprogram_Type (Base_Type (E))
and then Has_Foreign_Convention (E)
then
-
- -- A pragma Convention in an instance may apply to the subtype
- -- created for a formal, in which case we have already verified
- -- that conventions of actual and formal match and there is nothing
- -- to flag on the subtype.
-
- if In_Instance then
- null;
- else
- Set_Can_Use_Internal_Rep (E, False);
- end if;
+ Set_Can_Use_Internal_Rep (E, False);
end if;
-- If E is an object, including a component, and the type of E is an
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-12-05 12:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-05 12:23 [Ada] Fix indirect calls to imported subprograms within generic Pierre-Marie de Rodat
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).