From patchwork Wed Mar 14 16:04:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tristan Gingold X-Patchwork-Id: 146664 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 88313B6EF4 for ; Thu, 15 Mar 2012 03:05:01 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1332345902; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:Content-Type:Content-Transfer-Encoding:Subject: Date:Message-Id:Cc:To:Mime-Version:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=RRU0mki3Il1QDJiL1neutELIRT4=; b=nkz6vWtjcB7YMkL 2g4eEFqLp1muYUQ58tlf0KNA9n9jVICV0new+sMb7Gcsa4e41qF4+z0DHmiJ63pW oijfcCDUdJp8Vk1TASj/Ind2xIMVbJXgdFUWb1sQV3C+a004LtQeQxrPaF4ltznc Y38Odd/tc8/AmXh1x5jqZhUGm9JQ= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:Content-Type:Content-Transfer-Encoding:Subject:Date:Message-Id:Cc:To:Mime-Version:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Hjki5Zz2S2W+/W8uMQ6Dfo7A/2SVZrZPOotgvapSjfC3/uN2fTBuGtGhNi3SEb 3P6tzlr6m2f9Ebn+1vRvGt2qiCv9D5ku8/c/tEWqtsDIa6hRCq3SJTtIqvK7HkQw f0jlm4b+jzqRhxvKCh/yU0gHb5T+oK+njqK5Hf5xHMu9o=; Received: (qmail 7423 invoked by alias); 14 Mar 2012 16:04:56 -0000 Received: (qmail 7414 invoked by uid 22791); 14 Mar 2012 16:04:55 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_NV, TW_RG X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Mar 2012 16:04:40 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id A9D5C29002E; Wed, 14 Mar 2012 17:04:41 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wvNVmqaOQ4aa; Wed, 14 Mar 2012 17:04:41 +0100 (CET) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 914FA290026; Wed, 14 Mar 2012 17:04:41 +0100 (CET) From: Tristan Gingold Subject: [Patch/cfgexpand]: also consider assembler_name to call expand_main_function Date: Wed, 14 Mar 2012 17:04:39 +0100 Message-Id: <875C6F56-7161-48DF-91FB-3A01891F8289@adacore.com> Cc: Richard Guenther , Eric Botcazou To: GCC Patches Mime-Version: 1.0 (Apple Message framework v1257) X-IsSubscribed: yes 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 Hi, the code to call expand_main_function currently only checks DECL_NAME. This leads to a hack in ada/gcc-interface/utils.c to handle the gnatbind generated file that could declare: package ada_main is … function my_main (argc : Integer; argv : System.Address; envp : System.Address) return Integer; pragma Export (C, my_main, "main"); … end ada_main; But expand_main_function is also called for function whose name is main but assembly name isn't. Eg: package pkg is procedure main; end pkg; So I think we should consider the assembler name is set, otherwise the decl name. Manually tested on ia64-hp-openvms (where this issue was discovered). No C regressions for x86_64-darwin. Ok for trunk ? Tristan. gcc/ 2012-03-14 Tristan Gingold * cfgexpand.c (gimple_expand_cfg): Consider the assembly name to call expand_main_function. gcc/ada/ 2012-03-14 Tristan Gingold * gcc-interface/utils.c (create_subprog_decl): Do not override DECL_NAME if asm_name is set. diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 2f38bb4..8693876 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -4501,8 +4501,12 @@ gimple_expand_cfg (void) /* If this function is `main', emit a call to `__main' to run global initializers, etc. */ if (DECL_NAME (current_function_decl) - && MAIN_NAME_P (DECL_NAME (current_function_decl)) - && DECL_FILE_SCOPE_P (current_function_decl)) + && DECL_FILE_SCOPE_P (current_function_decl) + && main_identifier_node != NULL_TREE + && ((!DECL_ASSEMBLER_NAME_SET_P (current_function_decl) + && MAIN_NAME_P (DECL_NAME (current_function_decl))) + || decl_assembler_name_equal (current_function_decl, + main_identifier_node))) expand_main_function (); /* Initialize the stack_protect_guard field. This must happen after the diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 7383358..81a1a0a 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -1899,18 +1899,7 @@ create_subprog_decl (tree subprog_name, tree asm_name, tree subprog_type, DECL_RESULT (subprog_decl) = result_decl; if (asm_name) - { - SET_DECL_ASSEMBLER_NAME (subprog_decl, asm_name); - - /* The expand_main_function circuitry expects "main_identifier_node" to - designate the DECL_NAME of the 'main' entry point, in turn expected - to be declared as the "main" function literally by default. Ada - program entry points are typically declared with a different name - within the binder generated file, exported as 'main' to satisfy the - system expectations. Force main_identifier_node in this case. */ - if (asm_name == main_identifier_node) - DECL_NAME (subprog_decl) = main_identifier_node; - } + SET_DECL_ASSEMBLER_NAME (subprog_decl, asm_name); /* Add this decl to the current binding level. */ gnat_pushdecl (subprog_decl, gnat_node);