From 665e80ca5ec84ccf77d5e18d7ca802d38d5e270d Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 19 Jan 2021 10:43:15 +0100 Subject: Fix PR ada/98740 It's a long-standing GENERIC tree sharing issue. gcc/ada/ChangeLog: PR ada/98740 * gcc-interface/trans.c (add_decl_expr): Always mark TYPE_ADA_SIZE. --- gcc/ada/gcc-interface/trans.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gcc/ada/gcc-interface') diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 4ab26d3..6402c73 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -8479,15 +8479,16 @@ add_decl_expr (tree gnu_decl, Node_Id gnat_node) MARK_VISITED (DECL_SIZE_UNIT (gnu_decl)); MARK_VISITED (DECL_INITIAL (gnu_decl)); } - /* In any case, we have to deal with our own TYPE_ADA_SIZE field. */ - else if (TREE_CODE (gnu_decl) == TYPE_DECL - && RECORD_OR_UNION_TYPE_P (type) - && !TYPE_FAT_POINTER_P (type)) - MARK_VISITED (TYPE_ADA_SIZE (type)); } else add_stmt_with_node (gnu_stmt, gnat_node); + /* Mark our TYPE_ADA_SIZE field now since it will not be gimplified. */ + if (TREE_CODE (gnu_decl) == TYPE_DECL + && RECORD_OR_UNION_TYPE_P (type) + && !TYPE_FAT_POINTER_P (type)) + MARK_VISITED (TYPE_ADA_SIZE (type)); + /* If this is a variable and an initializer is attached to it, it must be valid for the context. Similar to init_const in create_var_decl. */ if (TREE_CODE (gnu_decl) == VAR_DECL -- cgit v1.1 From 5d01fc7c11606fa0fa36210309df6b10b6e07775 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 25 Jan 2021 11:27:29 +0100 Subject: Fix internal error on extension with interface at -O2 This is a regression present on the mainline, 10 and 9 branches, in the form of an internal error with the Ada compiler when a covariant-only thunk is inlined into its caller. gcc/ada/ * gcc-interface/trans.c (make_covariant_thunk): Set the DECL_CONTEXT of the parameters and do not set TREE_PUBLIC on the thunk. (maybe_make_gnu_thunk): Pass the alias to the covariant thunk. * gcc-interface/utils.c (finish_subprog_decl): Set the DECL_CONTEXT of the parameters here... (begin_subprog_body): ...instead of here. gcc/testsuite/ * gnat.dg/thunk2.adb, gnat.dg/thunk2.ads: New test. * gnat.dg/thunk2_pkg.ads: New helper. --- gcc/ada/gcc-interface/trans.c | 24 ++++++++++++++---------- gcc/ada/gcc-interface/utils.c | 12 ++++++------ 2 files changed, 20 insertions(+), 16 deletions(-) (limited to 'gcc/ada/gcc-interface') diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 6402c73..ae7a52f 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -10612,7 +10612,7 @@ make_alias_for_thunk (tree target) return alias; } -/* Create the covariant part of the {GNAT,GNU}_THUNK. */ +/* Create the local covariant part of {GNAT,GNU}_THUNK. */ static tree make_covariant_thunk (Entity_Id gnat_thunk, tree gnu_thunk) @@ -10623,6 +10623,11 @@ make_covariant_thunk (Entity_Id gnat_thunk, tree gnu_thunk) gnu_name, TREE_TYPE (gnu_thunk)); DECL_ARGUMENTS (gnu_cv_thunk) = copy_list (DECL_ARGUMENTS (gnu_thunk)); + for (tree param_decl = DECL_ARGUMENTS (gnu_cv_thunk); + param_decl; + param_decl = DECL_CHAIN (param_decl)) + DECL_CONTEXT (param_decl) = gnu_cv_thunk; + DECL_RESULT (gnu_cv_thunk) = copy_node (DECL_RESULT (gnu_thunk)); DECL_CONTEXT (DECL_RESULT (gnu_cv_thunk)) = gnu_cv_thunk; @@ -10630,7 +10635,6 @@ make_covariant_thunk (Entity_Id gnat_thunk, tree gnu_thunk) DECL_CONTEXT (gnu_cv_thunk) = DECL_CONTEXT (gnu_thunk); TREE_READONLY (gnu_cv_thunk) = TREE_READONLY (gnu_thunk); TREE_THIS_VOLATILE (gnu_cv_thunk) = TREE_THIS_VOLATILE (gnu_thunk); - TREE_PUBLIC (gnu_cv_thunk) = TREE_PUBLIC (gnu_thunk); DECL_ARTIFICIAL (gnu_cv_thunk) = 1; return gnu_cv_thunk; @@ -10760,6 +10764,12 @@ maybe_make_gnu_thunk (Entity_Id gnat_thunk, tree gnu_thunk) cgraph_node *target_node = cgraph_node::get_create (gnu_target); + /* We may also need to create an alias for the target in order to make + the call local, depending on the linkage of the target. */ + tree gnu_alias = use_alias_for_thunk_p (gnu_target) + ? make_alias_for_thunk (gnu_target) + : gnu_target; + /* If the return type of the target is a controlling type, then we need both an usual this thunk and a covariant thunk in this order: @@ -10772,17 +10782,11 @@ maybe_make_gnu_thunk (Entity_Id gnat_thunk, tree gnu_thunk) tree gnu_cv_thunk = make_covariant_thunk (gnat_thunk, gnu_thunk); target_node->create_thunk (gnu_cv_thunk, gnu_target, false, - fixed_offset, 0, 0, - NULL_TREE, gnu_target); + NULL_TREE, gnu_alias); - gnu_target = gnu_cv_thunk; + gnu_alias = gnu_target = gnu_cv_thunk; } - /* We may also need to create an alias for the target in order to make - the call local, depending on the linkage of the target. */ - tree gnu_alias = use_alias_for_thunk_p (gnu_target) - ? make_alias_for_thunk (gnu_target) - : gnu_target; - target_node->create_thunk (gnu_thunk, gnu_target, true, fixed_offset, virtual_value, indirect_offset, virtual_offset, gnu_alias); diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 494f60e..d52220a 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -3521,6 +3521,12 @@ create_subprog_decl (tree name, tree asm_name, tree type, tree param_decl_list, void finish_subprog_decl (tree decl, tree asm_name, tree type) { + /* DECL_ARGUMENTS is set by the caller, but not its context. */ + for (tree param_decl = DECL_ARGUMENTS (decl); + param_decl; + param_decl = DECL_CHAIN (param_decl)) + DECL_CONTEXT (param_decl) = decl; + tree result_decl = build_decl (DECL_SOURCE_LOCATION (decl), RESULT_DECL, NULL_TREE, TREE_TYPE (type)); @@ -3566,8 +3572,6 @@ finish_subprog_decl (tree decl, tree asm_name, tree type) void begin_subprog_body (tree subprog_decl) { - tree param_decl; - announce_function (subprog_decl); /* This function is being defined. */ @@ -3583,10 +3587,6 @@ begin_subprog_body (tree subprog_decl) /* Enter a new binding level and show that all the parameters belong to this function. */ gnat_pushlevel (); - - for (param_decl = DECL_ARGUMENTS (subprog_decl); param_decl; - param_decl = DECL_CHAIN (param_decl)) - DECL_CONTEXT (param_decl) = subprog_decl; } /* Finish translating the current subprogram and set its BODY. */ -- cgit v1.1 From 9c41bcc59c237aaa629e271f88c20a90cb8e0af5 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 26 Jan 2021 18:54:26 +0100 Subject: Fix PR ada/98228 This is the profiled bootstrap failure for s390x/Linux on the mainline, which has been introduced by the modref pass but actually exposing an existing issue in the maybe_pad_type function that is visible on s390x. The issue is too weak a test for the addressability of the inner component. gcc/ada/ Marius Hillenbrand PR ada/98228 * gcc-interface/utils.c (maybe_pad_type): Test the size of the new packable type instead of its alignment for addressability's sake. --- gcc/ada/gcc-interface/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/ada/gcc-interface') diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index d52220a..c503bfb 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -1571,7 +1571,7 @@ maybe_pad_type (tree type, tree size, unsigned int align, { tree packable_type = make_packable_type (type, true, align); if (TYPE_MODE (packable_type) != BLKmode - && align >= TYPE_ALIGN (packable_type)) + && compare_tree_int (TYPE_SIZE (packable_type), align) <= 0) type = packable_type; } -- cgit v1.1