From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101761 invoked by alias); 5 Dec 2017 12:23:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 101748 invoked by uid 89); 5 Dec 2017 12:23:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=disconnected, foreign, our X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Dec 2017 12:23:53 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7FD32116E13; Tue, 5 Dec 2017 07:23:52 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id VGVzKOCCxjXx; Tue, 5 Dec 2017 07:23:52 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 6F561116E10; Tue, 5 Dec 2017 07:23:52 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4862) id 6BD4F379; Tue, 5 Dec 2017 07:23:52 -0500 (EST) Date: Tue, 05 Dec 2017 12:23:00 -0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Olivier Hainque Subject: [Ada] Fix indirect calls to imported subprograms within generic Message-ID: <20171205122352.GA15912@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vkogqOf2sHV7VnPd" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00209.txt.bz2 --vkogqOf2sHV7VnPd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1437 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 * sem_util.adb (Set_Convention): Always clear Can_Use_Internal_Rep on access to subprogram types with foreign convention. --vkogqOf2sHV7VnPd Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 840 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 --vkogqOf2sHV7VnPd--