aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-04-29 09:15:13 +0200
committerMarc Poulhiès <poulhies@adacore.com>2024-06-14 09:34:50 +0200
commit55ceb87a72fee45a9a3e547a4e688f31d376a95a (patch)
tree2ec17a9279632c17d491d50086fcafa42bb56dcb /gcc/ada
parentcac993e84ea363dc593799ad1a6d0db5d0165f16 (diff)
downloadgcc-55ceb87a72fee45a9a3e547a4e688f31d376a95a.zip
gcc-55ceb87a72fee45a9a3e547a4e688f31d376a95a.tar.gz
gcc-55ceb87a72fee45a9a3e547a4e688f31d376a95a.tar.bz2
ada: Do not create null GCC thunks
This prevents Gigi from creating null GCC thunks, i.e. thunks that have all their internal parameters set to zero, replacing them with aliases. They can arise in degenerate cases and null thunks would trip on an assertion in former_thunk_p when they are later optimized. gcc/ada/ PR ada/109817 * gcc-interface/trans.cc (maybe_make_gnu_thunk): Create an alias instead of a null thunk.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/gcc-interface/trans.cc29
1 files changed, 19 insertions, 10 deletions
diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
index 93978c0..5256095 100644
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -11093,6 +11093,16 @@ maybe_make_gnu_thunk (Entity_Id gnat_thunk, tree gnu_thunk)
tree gnu_interface_offset
= gnu_interface_tag ? byte_position (gnu_interface_tag) : NULL_TREE;
+ /* But we generate a call to the Thunk_Entity in the thunk. */
+ tree gnu_target
+ = gnat_to_gnu_entity (Thunk_Entity (gnat_thunk), NULL_TREE, false);
+
+ /* If the target is local, then thunk and target must have the same context
+ because cgraph_node::expand_thunk can only forward the static chain. */
+ if (DECL_STATIC_CHAIN (gnu_target)
+ && DECL_CONTEXT (gnu_thunk) != DECL_CONTEXT (gnu_target))
+ return false;
+
/* There are three ways to retrieve the offset between the interface view
and the base object. Either the controlling type covers the interface
type and the offset of the corresponding tag is fixed, in which case it
@@ -11111,6 +11121,15 @@ maybe_make_gnu_thunk (Entity_Id gnat_thunk, tree gnu_thunk)
virtual_value = 0;
virtual_offset = NULL_TREE;
indirect_offset = 0;
+
+ /* Do not create a null thunk, instead make it an alias. */
+ if (fixed_offset == 0)
+ {
+ SET_DECL_ASSEMBLER_NAME (gnu_thunk, DECL_ASSEMBLER_NAME (gnu_target));
+ (void) cgraph_node::get_create (gnu_target);
+ (void) cgraph_node::create_alias (gnu_thunk, gnu_target);
+ return true;
+ }
}
else if (!gnu_interface_offset
&& !Is_Variable_Size_Record (gnat_controlling_type))
@@ -11132,16 +11151,6 @@ maybe_make_gnu_thunk (Entity_Id gnat_thunk, tree gnu_thunk)
indirect_offset = (HOST_WIDE_INT) (POINTER_SIZE / BITS_PER_UNIT);
}
- /* But we generate a call to the Thunk_Entity in the thunk. */
- tree gnu_target
- = gnat_to_gnu_entity (Thunk_Entity (gnat_thunk), NULL_TREE, false);
-
- /* If the target is local, then thunk and target must have the same context
- because cgraph_node::expand_thunk can only forward the static chain. */
- if (DECL_STATIC_CHAIN (gnu_target)
- && DECL_CONTEXT (gnu_thunk) != DECL_CONTEXT (gnu_target))
- return false;
-
/* If the target returns by invisible reference and is external, apply the
same transformation as Subprogram_Body_to_gnu here. */
if (TREE_ADDRESSABLE (TREE_TYPE (gnu_target))