[PATCH] D102518: [Demangle][Rust] Parse bool constants

Tomasz Miąsko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 14 11:01:35 PDT 2021


tmiasko created this revision.
tmiasko added a reviewer: dblaikie.
Herald added subscribers: JDevlieghere, hiraditya.
tmiasko requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102518

Files:
  llvm/include/llvm/Demangle/RustDemangle.h
  llvm/lib/Demangle/RustDemangle.cpp
  llvm/test/Demangle/rust.test


Index: llvm/test/Demangle/rust.test
===================================================================
--- llvm/test/Demangle/rust.test
+++ llvm/test/Demangle/rust.test
@@ -191,6 +191,22 @@
 CHECK: u64::<0>
        _RIC3u64Ky0_E
 
+; Bool constants
+
+CHECK: bool::<false>
+       _RIC4boolKb0_E
+
+CHECK: bool::<true>
+       _RIC4boolKb1_E
+
+; Invalid bool constants
+
+CHECK: _RIC4boolKb2_E
+       _RIC4boolKb2_E
+
+CHECK: _RIC4boolKbn0_E
+       _RIC4boolKbn0_E
+
 ; Invalid mangled characters
 
 CHECK: _RNvC2a.1c
Index: llvm/lib/Demangle/RustDemangle.cpp
===================================================================
--- llvm/lib/Demangle/RustDemangle.cpp
+++ llvm/lib/Demangle/RustDemangle.cpp
@@ -411,11 +411,14 @@
     case BasicType::USize:
       demangleConstInt();
       break;
+    case BasicType::Bool:
+      demangleConstBool();
+      break;
     case BasicType::Placeholder:
       print('_');
       break;
     default:
-      // FIXME demangle backreferences, bool constants, and char constants.
+      // FIXME demangle backreferences and char constants.
       Error = true;
       break;
     }
@@ -439,6 +442,19 @@
   }
 }
 
+// <const-data> = "0_" // false
+//              | "1_" // true
+void Demangler::demangleConstBool() {
+  StringView HexDigits;
+  parseHexNumber(HexDigits);
+  if (HexDigits == "0")
+    print("false");
+  else if (HexDigits == "1")
+    print("true");
+  else
+    Error = true;
+}
+
 // <undisambiguated-identifier> = ["u"] <decimal-number> ["_"] <bytes>
 Identifier Demangler::parseIdentifier() {
   bool Punycode = consumeIf('u');
Index: llvm/include/llvm/Demangle/RustDemangle.h
===================================================================
--- llvm/include/llvm/Demangle/RustDemangle.h
+++ llvm/include/llvm/Demangle/RustDemangle.h
@@ -80,6 +80,7 @@
   void demangleType();
   void demangleConst();
   void demangleConstInt();
+  void demangleConstBool();
 
   Identifier parseIdentifier();
   uint64_t parseOptionalBase62Number(char Tag);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102518.345505.patch
Type: text/x-patch
Size: 2015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210514/9d87bc6c/attachment.bin>


More information about the llvm-commits mailing list