From patchwork Mon Sep 23 08:10:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1165841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509428-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ca8uZpfW"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46cH7m0t8Lz9sP6 for ; Mon, 23 Sep 2019 18:10:42 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=w8NT9IyYpgF+S4ZP V8rBc2pybqW/LA8j7WWvJwFxYLPhsr3OtYBoua85/XaFpwTdVJhylS6YHvXyauyv qX3w3QaH4J7pW3PWwS2sX3MI9+noB1rIhKwo/kWa0+XmmdwOzncrFzXC55dNcBPT LvYbazJ1G2PQFIh7EN3vOsdu4kE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=3IMMcR7/Ck0kNZX0nfKsMx dBEGg=; b=ca8uZpfWtJSjD/3dKVNH/In3Mc6zOhnfzgaSkmOdXYwlhK+5+hLUxD 7J3JexatU3jQTKk9AIzgLV37HejAM9mRUeENYOD7C4LpEGa2NSRXToHDiYW2R9+p D71+YXe8rpyNrku68HMiWa/1p8mMZtZQgksJrvhkTwmSLTJ/jcH9Y= Received: (qmail 63844 invoked by alias); 23 Sep 2019 08:10:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 63458 invoked by uid 89); 23 Sep 2019 08:10:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.9 required=5.0 tests=BAYES_00, BODY_QUOTE_MALF_MSGID, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=views X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Sep 2019 08:10:22 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 2961C81390 for ; Mon, 23 Sep 2019 10:10:20 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FqKTskpItA2e for ; Mon, 23 Sep 2019 10:10:20 +0200 (CEST) Received: from polaris.localnet (unknown [IPv6:2a01:e35:8a16:3850:1a03:73ff:fe45:373a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 037EA8138C for ; Mon, 23 Sep 2019 10:10:19 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix run-time segfault with private access-to-subprogram type Date: Mon, 23 Sep 2019 10:10:18 +0200 Message-ID: <32029361.e12EvXt3TJ@polaris> MIME-Version: 1.0 This fixes a segfault at run time in a very peculiar case where an access-to- subprogram type is declared as private and used to pass the address of a local subprogram and dereference it using different views of the type. Tested on x86_64-suse-linux, applied on all active branches. 2019-09-23 Eric Botcazou * gcc-interface/trans.c (Attribute_to_gnu): Test Can_Use_Internal_Rep on the underlying type of the node. (Call_to_gnu): Likewise with the type of the prefix. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 275988) +++ gcc-interface/trans.c (working copy) @@ -2254,32 +2254,29 @@ Attribute_to_gnu (Node_Id gnat_node, tre /* For other address attributes applied to a nested function, find an inner ADDR_EXPR and annotate it so that we can issue a useful warning with -Wtrampolines. */ - else if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (gnu_prefix))) - { - gnu_expr = remove_conversions (gnu_result, false); - - if (TREE_CODE (gnu_expr) == ADDR_EXPR - && decl_function_context (TREE_OPERAND (gnu_expr, 0))) - { - set_expr_location_from_node (gnu_expr, gnat_node); - - /* Also check the inlining status. */ - check_inlining_for_nested_subprog (TREE_OPERAND (gnu_expr, 0)); - - /* Moreover, for 'Access or 'Unrestricted_Access with non- - foreign-compatible representation, mark the ADDR_EXPR so - that we can build a descriptor instead of a trampoline. */ - if ((attribute == Attr_Access - || attribute == Attr_Unrestricted_Access) - && targetm.calls.custom_function_descriptors > 0 - && Can_Use_Internal_Rep (Etype (gnat_node))) - FUNC_ADDR_BY_DESCRIPTOR (gnu_expr) = 1; - - /* Otherwise, we need to check that we are not violating the - No_Implicit_Dynamic_Code restriction. */ - else if (targetm.calls.custom_function_descriptors != 0) - Check_Implicit_Dynamic_Code_Allowed (gnat_node); - } + else if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (gnu_prefix)) + && (gnu_expr = remove_conversions (gnu_result, false)) + && TREE_CODE (gnu_expr) == ADDR_EXPR + && decl_function_context (TREE_OPERAND (gnu_expr, 0))) + { + set_expr_location_from_node (gnu_expr, gnat_node); + + /* Also check the inlining status. */ + check_inlining_for_nested_subprog (TREE_OPERAND (gnu_expr, 0)); + + /* Moreover, for 'Access or 'Unrestricted_Access with non- + foreign-compatible representation, mark the ADDR_EXPR so + that we can build a descriptor instead of a trampoline. */ + if ((attribute == Attr_Access + || attribute == Attr_Unrestricted_Access) + && targetm.calls.custom_function_descriptors > 0 + && Can_Use_Internal_Rep (Underlying_Type (Etype (gnat_node)))) + FUNC_ADDR_BY_DESCRIPTOR (gnu_expr) = 1; + + /* Otherwise, we need to check that we are not violating the + No_Implicit_Dynamic_Code restriction. */ + else if (targetm.calls.custom_function_descriptors != 0) + Check_Implicit_Dynamic_Code_Allowed (gnat_node); } break; @@ -5111,7 +5108,8 @@ Call_to_gnu (Node_Id gnat_node, tree *gn /* If the access type doesn't require foreign-compatible representation, be prepared for descriptors. */ if (targetm.calls.custom_function_descriptors > 0 - && Can_Use_Internal_Rep (Etype (Prefix (Name (gnat_node))))) + && Can_Use_Internal_Rep + (Underlying_Type (Etype (Prefix (Name (gnat_node)))))) by_descriptor = true; } else if (Nkind (Name (gnat_node)) == N_Attribute_Reference)