[Rust,front-end,v2,01/37] Use DW_ATE_UTF for the Rust 'char' type
Commit Message
From: Tom Tromey <tom@tromey.com>
The Rust 'char' type should use the DWARF DW_ATE_UTF encoding.
---
gcc/dwarf2out.cc | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
Comments
On 8/24/22 04:59, herron.philip@googlemail.com wrote:
> From: Tom Tromey <tom@tromey.com>
>
> The Rust 'char' type should use the DWARF DW_ATE_UTF encoding.
The DWARF changes are OK.
> ---
> gcc/dwarf2out.cc | 23 ++++++++++++++++++++++-
> 1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
> index e3920c898f5..a8bccbabca4 100644
> --- a/gcc/dwarf2out.cc
> +++ b/gcc/dwarf2out.cc
> @@ -5600,6 +5600,16 @@ is_fortran (const_tree decl)
> return is_fortran ();
> }
>
> +/* Return TRUE if the language is Rust. */
> +
> +static inline bool
> +is_rust ()
> +{
> + unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
> +
> + return lang == DW_LANG_Rust || lang == DW_LANG_Rust_old;
> +}
> +
> /* Return TRUE if the language is Ada. */
>
> static inline bool
> @@ -13231,7 +13241,11 @@ base_type_die (tree type, bool reverse)
> }
> if (TYPE_STRING_FLAG (type))
> {
> - if (TYPE_UNSIGNED (type))
> + if ((dwarf_version >= 4 || !dwarf_strict)
> + && is_rust ()
> + && int_size_in_bytes (type) == 4)
> + encoding = DW_ATE_UTF;
> + else if (TYPE_UNSIGNED (type))
> encoding = DW_ATE_unsigned_char;
> else
> encoding = DW_ATE_signed_char;
> @@ -25201,6 +25215,13 @@ gen_compile_unit_die (const char *filename)
> }
> else if (strcmp (language_string, "GNU F77") == 0)
> language = DW_LANG_Fortran77;
> + else if (strcmp (language_string, "GNU Rust") == 0)
> + {
> + if (dwarf_version >= 5 || !dwarf_strict)
> + language = DW_LANG_Rust;
> + else
> + language = DW_LANG_Rust_old;
> + }
> else if (dwarf_version >= 3 || !dwarf_strict)
> {
> if (strcmp (language_string, "GNU Ada") == 0)
@@ -5600,6 +5600,16 @@ is_fortran (const_tree decl)
return is_fortran ();
}
+/* Return TRUE if the language is Rust. */
+
+static inline bool
+is_rust ()
+{
+ unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
+
+ return lang == DW_LANG_Rust || lang == DW_LANG_Rust_old;
+}
+
/* Return TRUE if the language is Ada. */
static inline bool
@@ -13231,7 +13241,11 @@ base_type_die (tree type, bool reverse)
}
if (TYPE_STRING_FLAG (type))
{
- if (TYPE_UNSIGNED (type))
+ if ((dwarf_version >= 4 || !dwarf_strict)
+ && is_rust ()
+ && int_size_in_bytes (type) == 4)
+ encoding = DW_ATE_UTF;
+ else if (TYPE_UNSIGNED (type))
encoding = DW_ATE_unsigned_char;
else
encoding = DW_ATE_signed_char;
@@ -25201,6 +25215,13 @@ gen_compile_unit_die (const char *filename)
}
else if (strcmp (language_string, "GNU F77") == 0)
language = DW_LANG_Fortran77;
+ else if (strcmp (language_string, "GNU Rust") == 0)
+ {
+ if (dwarf_version >= 5 || !dwarf_strict)
+ language = DW_LANG_Rust;
+ else
+ language = DW_LANG_Rust_old;
+ }
else if (dwarf_version >= 3 || !dwarf_strict)
{
if (strcmp (language_string, "GNU Ada") == 0)