From patchwork Fri Oct 11 08:19:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1174999 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-510720-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="Dkiw6MAy"; 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 46qLTj1TfLz9sP3 for ; Fri, 11 Oct 2019 19:19:35 +1100 (AEDT) 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=NBTmqSbjeYS1To8S iDfi9oxU61FpyUdkEV8ZR7bOowu9DPxWdGsQ0ayHJA6REYVEE6PlBJ4nHF/5YAQP wwKZ51z88L9xncIHUCwauxB5q77g/W9vSLQazTaIBeJw1ckGVLGRivkg03QdgKo3 XS15qDYSKZ7odV1ufSA5Kp7sEFI= 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=yRoOxiUEZpi4ue/sbmEAuZ UHmhk=; b=Dkiw6MAytW2SvCh4WsVZ7j+5pZnqDiS/YSEYp4RbqUwWgDju08UMeG jOnqH7THlEQcwz4oaqpePbdY5v8hmK/ngyJ+NmYFEl/yXtJit4MPzxIJwkQtTZkM vSSc5fHfiMfNOx9hZT2Ydizr+Mf9n+XbSLcUwMrHyIHKEIjxWoHaI= Received: (qmail 78340 invoked by alias); 11 Oct 2019 08:19:27 -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 78322 invoked by uid 89); 11 Oct 2019 08:19:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= 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; Fri, 11 Oct 2019 08:19:24 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id C65728138C for ; Fri, 11 Oct 2019 10:19:21 +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 LUvYRj05i1UO for ; Fri, 11 Oct 2019 10:19:21 +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 9876681386 for ; Fri, 11 Oct 2019 10:19:21 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Emit debug info for named numbers Date: Fri, 11 Oct 2019 10:19:19 +0200 Message-ID: <2181743.yql8yhLG9m@polaris> MIME-Version: 1.0 You can declare named numbers in Ada with the syntax: Pi : constant := 3.14159 and the compiler automatically resolves the underlying type. But it wouldn't emit debug info for the declaration although DW_TAG_constant is a perfect fit. Tested on x86_64-suse-linux, applied on the mainline. 2019-10-11 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : New case to deal with the definition of named numbers. : Minor tweaks. Set DECL_IGNORED_P on the CONST_DECL if a corresponding variable is built. * gcc-interface/trans.c (gnat_to_gnu) : Return error_mark_node instead of aborting on overflow for named numbers. : Reuse the case and deal with error_mark_node specifically. * gcc-interface/utils.c (create_var_decl): Do not set DECL_IGNORED_P on CONST_DECLs. (gnat_write_global_declarations): Output global constants. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 276859) +++ gcc-interface/decl.c (working copy) @@ -585,6 +585,29 @@ gnat_to_gnu_entity (Entity_Id gnat_entit gcc_unreachable (); } + case E_Named_Integer: + case E_Named_Real: + { + tree gnu_ext_name = NULL_TREE; + + if (Is_Public (gnat_entity)) + gnu_ext_name = create_concat_name (gnat_entity, NULL); + + /* All references are supposed to be folded in the front-end. */ + gcc_assert (definition && gnu_expr); + + gnu_type = gnat_to_gnu_type (Etype (gnat_entity)); + gnu_expr = convert (gnu_type, gnu_expr); + + /* Build a CONST_DECL for debugging purposes exclusively. */ + gnu_decl + = create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type, + gnu_expr, true, Is_Public (gnat_entity), + false, false, false, artificial_p, + debug_info_p, NULL, gnat_entity, true); + } + break; + case E_Constant: /* Ignore constant definitions already marked with the error node. See the N_Object_Declaration case of gnat_to_gnu for the rationale. */ @@ -1519,18 +1542,16 @@ gnat_to_gnu_entity (Entity_Id gnat_entit /* If this is a constant and we are defining it or it generates a real symbol at the object level and we are referencing it, we may want or need to have a true variable to represent it: - - if optimization isn't enabled, for debugging purposes, - if the constant is public and not overlaid on something else, - if its address is taken, - - if either itself or its type is aliased. */ + - if it is aliased, + - if optimization isn't enabled, for debugging purposes. */ if (TREE_CODE (gnu_decl) == CONST_DECL && (definition || Sloc (gnat_entity) > Standard_Location) - && ((!optimize && debug_info_p) - || (Is_Public (gnat_entity) - && No (Address_Clause (gnat_entity))) + && ((Is_Public (gnat_entity) && No (Address_Clause (gnat_entity))) || Address_Taken (gnat_entity) || Is_Aliased (gnat_entity) - || Is_Aliased (gnat_type))) + || (!optimize && debug_info_p))) { tree gnu_corr_var = create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type, @@ -1540,6 +1561,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit attr_list, gnat_entity, false); SET_DECL_CONST_CORRESPONDING_VAR (gnu_decl, gnu_corr_var); + DECL_IGNORED_P (gnu_decl) = 1; } /* If this is a constant, even if we don't need a true variable, we Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 276859) +++ gcc-interface/trans.c (working copy) @@ -6881,11 +6881,17 @@ gnat_to_gnu (Node_Id gnat_node) gnu_result = UI_To_gnu (Intval (gnat_node), gnu_type); /* If the result overflows (meaning it doesn't fit in its base type), - abort. We would like to check that the value is within the range - of the subtype, but that causes problems with subtypes whose usage - will raise Constraint_Error and with biased representation, so - we don't. */ - gcc_assert (!TREE_OVERFLOW (gnu_result)); + abort, unless this is for a named number because that's not fatal. + We would like to check that the value is within the range of the + subtype, but that causes problems with subtypes whose usage will + raise Constraint_Error and also with biased representation. */ + if (TREE_OVERFLOW (gnu_result)) + { + if (Nkind (Parent (gnat_node)) == N_Number_Declaration) + gnu_result = error_mark_node; + else + gcc_unreachable (); + } } break; @@ -7030,6 +7036,7 @@ gnat_to_gnu (Node_Id gnat_node) break; case N_Object_Declaration: + case N_Number_Declaration: case N_Exception_Declaration: gnat_temp = Defining_Entity (gnat_node); gnu_result = alloc_stmt_list (); @@ -7052,8 +7059,15 @@ gnat_to_gnu (Node_Id gnat_node) gnu_expr = gnat_to_gnu (Expression (gnat_node)); - if (type_annotate_only && TREE_CODE (gnu_expr) == ERROR_MARK) - gnu_expr = NULL_TREE; + if (TREE_CODE (gnu_expr) == ERROR_MARK) + { + /* If this is a named number for which we cannot manipulate + the value, just skip the declaration altogether. */ + if (kind == N_Number_Declaration) + break; + else if (type_annotate_only) + gnu_expr = NULL_TREE; + } } else gnu_expr = NULL_TREE; @@ -7163,7 +7177,6 @@ gnat_to_gnu (Node_Id gnat_node) gnu_result = alloc_stmt_list (); break; - case N_Number_Declaration: case N_Package_Renaming_Declaration: /* These are fully handled in the front end. */ /* ??? For package renamings, find a way to use GENERIC namespaces so Index: gcc-interface/utils.c =================================================================== --- gcc-interface/utils.c (revision 276859) +++ gcc-interface/utils.c (working copy) @@ -2731,13 +2731,11 @@ create_var_decl (tree name, tree asm_nam && !have_global_bss_p ()) DECL_COMMON (var_decl) = 1; - /* Do not emit debug info for a CONST_DECL if optimization isn't enabled, - since we will create an associated variable. Likewise for an external - constant whose initializer is not absolute, because this would mean a - global relocation in a read-only section which runs afoul of the PE-COFF - run-time relocation mechanism. */ + /* Do not emit debug info if not requested, or for an external constant whose + initializer is not absolute because this would require a global relocation + in a read-only section which runs afoul of the PE-COFF run-time relocation + mechanism. */ if (!debug_info_p - || (TREE_CODE (var_decl) == CONST_DECL && !optimize) || (extern_flag && constant_p && init @@ -5840,6 +5838,11 @@ gnat_write_global_declarations (void) && DECL_FUNCTION_IS_DEF (iter)) debug_hooks->early_global_decl (iter); + /* Output global constants. */ + FOR_EACH_VEC_SAFE_ELT (global_decls, i, iter) + if (TREE_CODE (iter) == CONST_DECL && !DECL_IGNORED_P (iter)) + debug_hooks->early_global_decl (iter); + /* Then output the global variables. We need to do that after the debug information for global types is emitted so that they are finalized. Skip external global variables, unless we need to emit debug info for them: