aboutsummaryrefslogtreecommitdiff
path: root/gcc/dwarf2out.c
diff options
context:
space:
mode:
authorPierre-Marie de Rodat <derodat@adacore.com>2017-06-01 08:36:57 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2017-06-01 08:36:57 +0000
commit9285616cbd8a079a6a72f07b47880244114ee4b2 (patch)
treecdd7675142b8599bcec2e279fab4666ff82886c1 /gcc/dwarf2out.c
parent3fa4634c9250a7e0c51c1eac04d98b2fae032c60 (diff)
downloadgcc-9285616cbd8a079a6a72f07b47880244114ee4b2.zip
gcc-9285616cbd8a079a6a72f07b47880244114ee4b2.tar.gz
gcc-9285616cbd8a079a6a72f07b47880244114ee4b2.tar.bz2
DWARF: for variants, produce unsigned discr. when debug type is unsigned
In Ada, the Character type is supposed to be unsigned. However, depending on the sign of C char types, GNAT can materialize it as a signed type for code generation purposes. When this is the case, GNAT also attach a debug type to it so it is represented as an unsigned base type in the debug information. This change adapts record variant parts processing in the DWARF back-end so that when the debug type of discriminant is unsigned while discriminant values are signed themselves, we output unsigned discriminant values in DWARF. gcc/ * dwarf2out.c (get_discr_value): Call the get_debug_type hook on the type of the input discriminant value. Convert the discriminant value of signedness vary. gcc/testsuite/ * gnat.dg/debug11.adb: New testcase. From-SVN: r248773
Diffstat (limited to 'gcc/dwarf2out.c')
-rw-r--r--gcc/dwarf2out.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5ff45eb..7983f52 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -23701,14 +23701,33 @@ analyze_discr_in_predicate (tree operand, tree struct_type)
static bool
get_discr_value (tree src, dw_discr_value *dest)
{
- bool is_unsigned = TYPE_UNSIGNED (TREE_TYPE (src));
+ tree discr_type = TREE_TYPE (src);
- if (TREE_CODE (src) != INTEGER_CST
- || !(is_unsigned ? tree_fits_uhwi_p (src) : tree_fits_shwi_p (src)))
+ if (lang_hooks.types.get_debug_type)
+ {
+ tree debug_type = lang_hooks.types.get_debug_type (discr_type);
+ if (debug_type != NULL)
+ discr_type = debug_type;
+ }
+
+ if (TREE_CODE (src) != INTEGER_CST || !INTEGRAL_TYPE_P (discr_type))
+ return false;
+
+ /* Signedness can vary between the original type and the debug type. This
+ can happen for character types in Ada for instance: the character type
+ used for code generation can be signed, to be compatible with the C one,
+ but from a debugger point of view, it must be unsigned. */
+ bool is_orig_unsigned = TYPE_UNSIGNED (TREE_TYPE (src));
+ bool is_debug_unsigned = TYPE_UNSIGNED (discr_type);
+
+ if (is_orig_unsigned != is_debug_unsigned)
+ src = fold_convert (discr_type, src);
+
+ if (!(is_debug_unsigned ? tree_fits_uhwi_p (src) : tree_fits_shwi_p (src)))
return false;
- dest->pos = is_unsigned;
- if (is_unsigned)
+ dest->pos = is_debug_unsigned;
+ if (is_debug_unsigned)
dest->v.uval = tree_to_uhwi (src);
else
dest->v.sval = tree_to_shwi (src);