public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4631] Use DW_ATE_UTF for the Rust 'char' type
Date: Tue, 13 Dec 2022 13:16:50 +0000 (GMT)	[thread overview]
Message-ID: <20221213131650.90658383F20F@sourceware.org> (raw)

https://gcc.gnu.org/g:dd950cbbb97ff5ebc203cba6c2112edd322b6f35

commit r13-4631-gdd950cbbb97ff5ebc203cba6c2112edd322b6f35
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Aug 23 15:47:13 2022 +0100

    Use DW_ATE_UTF for the Rust 'char' type
    
    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>

Diff:
---
 gcc/dwarf2out.cc | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index e81044b8c48..ed06707a7b4 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -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.  */

                 reply	other threads:[~2022-12-13 13:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221213131650.90658383F20F@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).