From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Olivier Hainque <hainque@adacore.com>
Subject: [Ada] Fix indirect calls to imported subprograms within generic
Date: Tue, 05 Dec 2017 12:23:00 -0000 [thread overview]
Message-ID: <20171205122352.GA15912@adacore.com> (raw)
[-- 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
reply other threads:[~2017-12-05 12:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171205122352.GA15912@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hainque@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).