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 <hain...@adacore.com> * sem_util.adb (Set_Convention): Always clear Can_Use_Internal_Rep on access to subprogram types with foreign convention.
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