Skip to content
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ The current port status by category is:
(only usable in `const` generics on unstable Rust)
* **(UNPORTED)** recursion limits
* miscellaneous
* **(UNPORTED)** extraneous symbol suffix (e.g. `.llvm.*`) removal
* **ported** PRs:
* extraneous symbol suffix (e.g. `.llvm.*`) removal
* **(UNPORTED)** output size limits

Notable differences (intentionally) introduced by porting:
Expand Down
16 changes: 11 additions & 5 deletions rust-demangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,23 +827,29 @@ bool rust_demangle_with_callback(
rdm.version = 0;
rdm.bound_lifetime_depth = 0;

// Rust symbols use only [_0-9a-zA-Z] characters.
// Rust symbols only use ASCII characters.
for (const char *p = mangled; *p; p++) {
if (!(*p == '_' || IS_DIGIT(*p) || IS_LOWER(*p) || IS_UPPER(*p)))
if ((*p & 0x80) != 0)
return false;

if (*p == '.' && strncmp(p, ".llvm.", 6) == 0) {
// Ignore .llvm.<hash> suffixes
break;
}

rdm.sym_len++;
}

demangle_path(&rdm, true);

// Skip instantiating crate.
if (!rdm.errored && rdm.next < rdm.sym_len) {
if (!rdm.errored && rdm.next < rdm.sym_len && peek(&rdm) >= 'A' && peek(&rdm) <= 'Z') {
rdm.skipping_printing = true;
demangle_path(&rdm, false);
}

// It's an error to not reach the end.
rdm.errored |= rdm.next != rdm.sym_len;
// Print trailing garbage
print_str(&rdm, rdm.sym + rdm.next, rdm.sym_len - rdm.next);

return !rdm.errored;
}
Expand Down
4 changes: 0 additions & 4 deletions test-harness/tests/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,13 @@ fn demangle_exponential_explosion() {
);
}

// FIXME(eddyb) port the relevant functionality to C.
#[should_panic]
#[test]
fn demangle_thinlto() {
t_nohash!("_RC3foo.llvm.9D1C9369", "foo");
t_nohash!("_RC3foo.llvm.9D1C9369@@16", "foo");
t_nohash!("_RNvC9backtrace3foo.llvm.A5310EB9", "backtrace::foo");
}

// FIXME(eddyb) port the relevant functionality to C.
#[should_panic]
#[test]
fn demangle_extra_suffix() {
// From alexcrichton/rustc-demangle#27:
Expand Down