aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-06-18 13:34:04 -0600
committerTom Tromey <tom@tromey.com>2021-06-18 13:47:51 -0600
commit8dd844ad0ab6378e6f6317dd93883bc8f642e642 (patch)
treed3b96584a16fa603c1c8cd0607f446e757c92436 /gcc
parent231de190d1c8666748eb1c346d22c73946aba743 (diff)
downloadgcc-8dd844ad0ab6378e6f6317dd93883bc8f642e642.zip
gcc-8dd844ad0ab6378e6f6317dd93883bc8f642e642.tar.gz
gcc-8dd844ad0ab6378e6f6317dd93883bc8f642e642.tar.bz2
Use DW_ATE_UTF for the Rust 'char' type
The Rust 'char' type should use the DWARF DW_ATE_UTF encoding.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/dwarf2out.c16
-rw-r--r--gcc/rust/rust-gcc.cc6
-rw-r--r--gcc/testsuite/rust/debug/chartype.rs10
3 files changed, 27 insertions, 5 deletions
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 7252887..0ce8935 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -5498,6 +5498,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
@@ -12952,7 +12962,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;
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index e6c8858..3158c11 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -217,10 +217,8 @@ public:
Btype *wchar_type ()
{
- // i think this is meant to be 32 bit from
- // https://www.unicode.org/versions/Unicode13.0.0/ch03.pdf#G7404
- int precision = 32;
- tree wchar = make_unsigned_type (precision);
+ tree wchar = make_unsigned_type (32);
+ TYPE_STRING_FLAG (wchar) = 1;
return this->make_type (wchar);
}
diff --git a/gcc/testsuite/rust/debug/chartype.rs b/gcc/testsuite/rust/debug/chartype.rs
new file mode 100644
index 0000000..5504481
--- /dev/null
+++ b/gcc/testsuite/rust/debug/chartype.rs
@@ -0,0 +1,10 @@
+// 'char' should use DW_ATE_UTF
+fn main () {
+ let c = 'x';
+// { dg-do compile }
+// Use -w to avoid warnings about the unused variables
+// DW_ATE_UTF entered in DWARF 4.
+// { dg-options "-w -gdwarf-4 -dA" }
+// DW_ATE_UTF = 0x10
+// { dg-final { scan-assembler "0x10\[^\n\r]* DW_AT_encoding" } } */
+}