https://gcc.gnu.org/g:92359793fc3d8c94a6704e518555807227b21bea
commit 92359793fc3d8c94a6704e518555807227b21bea Author: Alexandre Oliva <ol...@adacore.com> Date: Thu Jun 27 09:11:27 2024 -0300 Map unpacked type to packed deduped type for debug info Avoid creating unnecessary copies of types in make_type_from_size. Cache the packed version of a biased type in TYPE_DEBUG_TYPE, so as to map the unpacked type to it. for gcc/ada/ChangeLog * gcc-interface/utils.cc (make_type_from_size): Cache packed variant, and map unpacked type to it in debug info. for gcc/testsuite/ChangeLog * gnat.dg/bias1.adb: Count occurrences of -7.*DW_AT_GNU_bias. Diff: --- gcc/ada/gcc-interface/utils.cc | 19 +++++++++++++++++++ gcc/testsuite/gnat.dg/bias1.adb | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc index d8d42f57b89..daf8d7ccdc5 100644 --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -1399,6 +1399,15 @@ make_type_from_size (tree type, tree size_tree, bool for_biased) || size > (Enable_128bit_Types ? 128 : LONG_LONG_TYPE_SIZE)) break; + /* If we've already created this type, the base type is supposed + to map to it. Check that it is what we expect. */ + if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type) + && (new_type = TYPE_DEBUG_TYPE (type)) + && TYPE_PRECISION (new_type) == size + && ((TREE_CODE (new_type) == INTEGER_TYPE + && TYPE_BIASED_REPRESENTATION_P (new_type)) == for_biased)) + return new_type; + /* The type should be an unsigned type if the original type is unsigned or if the lower bound is constant and non-negative or if the type is biased, see E_Signed_Integer_Subtype case of gnat_to_gnu_entity. */ @@ -1414,6 +1423,16 @@ make_type_from_size (tree type, tree size_tree, bool for_biased) TYPE_NAME (new_type) = TYPE_NAME (type); TYPE_BIASED_REPRESENTATION_P (new_type) = for_biased; SET_TYPE_RM_SIZE (new_type, bitsize_int (size)); + + /* Enable us to avoid creating the same narrower type multiple + times, and avoid duplication in debug information, by mapping + the wider type to the narrower version. If biasing is + different, we use the narrower type for debug information. */ + if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type) + && !TYPE_DEBUG_TYPE (type) + && biased_p == for_biased) + SET_TYPE_DEBUG_TYPE (type, new_type); + return new_type; case RECORD_TYPE: diff --git a/gcc/testsuite/gnat.dg/bias1.adb b/gcc/testsuite/gnat.dg/bias1.adb index 016a159b692..d9a00a1aa45 100644 --- a/gcc/testsuite/gnat.dg/bias1.adb +++ b/gcc/testsuite/gnat.dg/bias1.adb @@ -1,6 +1,7 @@ -- { dg-do compile } -- { dg-options "-cargs -g -dA -gnatws -fgnat-encodings=gdb -margs" } -- { dg-final { scan-assembler "DW_AT_GNU_bias" } } +-- { dg-final { scan-assembler-times "-7.*DW_AT_GNU_bias" 1 } } procedure Bias1 is type Small is range -7 .. -4; @@ -31,4 +32,4 @@ procedure Bias1 is begin null; -end Bias1; \ No newline at end of file +end Bias1;