]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use DW_ATE_UTF for the Rust 'char' type
authorTom Tromey <tom@tromey.com>
Tue, 23 Aug 2022 14:47:13 +0000 (15:47 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 13 Dec 2022 13:00:02 +0000 (14:00 +0100)
The Rust 'char' type should use the DWARF DW_ATE_UTF encoding.

gcc/
* dwarf2out.cc (is_rust): New.
(base_type_die): Use DW_ATE_UTF for the Rust 'char' type.
(gen_compile_unit_die): Handle "GNU Rust".

Co-authored-by: Mark Wielaard <mark@klomp.org>
Co-authored-by: Marc Poulhiès <dkm@kataplop.net>
gcc/dwarf2out.cc

index e81044b8c482e87a5536206fd120edc15c754836..ed06707a7b474a194ea7e02063be1083ac415643 100644 (file)
@@ -5600,6 +5600,17 @@ is_fortran (const_tree decl)
   return is_fortran ();
 }
 
+/* Return TRUE if the language is Rust.
+   Note, returns FALSE for dwarf_version < 5 && dwarf_strict. */
+
+static inline bool
+is_rust ()
+{
+  unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
+
+  return lang == DW_LANG_Rust;
+}
+
 /* Return TRUE if the language is Ada.  */
 
 static inline bool
@@ -13232,7 +13243,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;
@@ -25231,6 +25246,8 @@ gen_compile_unit_die (const char *filename)
        {
          if (strcmp (language_string, "GNU Go") == 0)
            language = DW_LANG_Go;
+         else if (strcmp (language_string, "GNU Rust") == 0)
+           language = DW_LANG_Rust;
        }
     }
   /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works.  */