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]

[Ada] Fix indirect calls to imported subprograms within generic


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: difs
Description: Text document


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