Skip to content

Commit e1cb00d

Browse files
eddybJeff Law
authored and
Jeff Law
committed
rust-demangle.c (looks_like_rust): Remove.
* rust-demangle.c (looks_like_rust): Remove. (rust_is_mangled): Don't check escapes. (is_prefixed_hash): Allow 0-9a-f permutations. (rust_demangle_sym): Don't bail on unknown escapes. * testsuite/rust-demangle-expected: Update 'main::$99$' test. From-SVN: r276539
1 parent e23390d commit e1cb00d

File tree

3 files changed

+34
-40
lines changed

3 files changed

+34
-40
lines changed

libiberty/ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-10-03 Eduard-Mihai Burtescu <[email protected]>
2+
3+
* rust-demangle.c (looks_like_rust): Remove.
4+
(rust_is_mangled): Don't check escapes.
5+
(is_prefixed_hash): Allow 0-9a-f permutations.
6+
(rust_demangle_sym): Don't bail on unknown escapes.
7+
* testsuite/rust-demangle-expected: Update 'main::$99$' test.
8+
19
2019-09-03 Eduard-Mihai Burtescu <[email protected]>
210

311
* rust-demangle.c (unescape): Remove.

libiberty/rust-demangle.c

+25-39
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ static const size_t hash_prefix_len = 3;
8585
static const size_t hash_len = 16;
8686

8787
static int is_prefixed_hash (const char *start);
88-
static int looks_like_rust (const char *sym, size_t len);
8988
static int parse_lower_hex_nibble (char nibble);
9089
static char parse_legacy_escape (const char **in);
9190

@@ -105,16 +104,13 @@ static char parse_legacy_escape (const char **in);
105104
negative (the rare Rust symbol is not demangled) so this sets
106105
the balance in favor of false negatives.
107106
108-
3. There must be no characters other than a-zA-Z0-9 and _.:$
109-
110-
4. There must be no unrecognized $-sign sequences.
111-
112-
5. There must be no sequence of three or more dots in a row ("..."). */
107+
3. There must be no characters other than a-zA-Z0-9 and _.:$ */
113108

114109
int
115110
rust_is_mangled (const char *sym)
116111
{
117112
size_t len, len_without_hash;
113+
const char *end;
118114

119115
if (!sym)
120116
return 0;
@@ -128,12 +124,22 @@ rust_is_mangled (const char *sym)
128124
if (!is_prefixed_hash (sym + len_without_hash))
129125
return 0;
130126

131-
return looks_like_rust (sym, len_without_hash);
127+
end = sym + len_without_hash;
128+
129+
while (sym < end)
130+
{
131+
if (*sym == '$' || *sym == '.' || *sym == '_' || *sym == ':'
132+
|| ISALNUM (*sym))
133+
sym++;
134+
else
135+
return 0;
136+
}
137+
138+
return 1;
132139
}
133140

134141
/* A hash is the prefix "::h" followed by 16 lowercase hex digits. The
135-
hex digits must comprise between 5 and 15 (inclusive) distinct
136-
digits. */
142+
hex digits must contain at least 5 distinct digits. */
137143

138144
static int
139145
is_prefixed_hash (const char *str)
@@ -162,28 +168,7 @@ is_prefixed_hash (const char *str)
162168
if (seen[i])
163169
count++;
164170

165-
return count >= 5 && count <= 15;
166-
}
167-
168-
static int
169-
looks_like_rust (const char *str, size_t len)
170-
{
171-
const char *end = str + len;
172-
173-
while (str < end)
174-
{
175-
if (*str == '$')
176-
{
177-
if (!parse_legacy_escape (&str))
178-
return 0;
179-
}
180-
else if (*str == '.' || *str == '_' || *str == ':' || ISALNUM (*str))
181-
str++;
182-
else
183-
return 0;
184-
}
185-
186-
return 1;
171+
return count >= 5;
187172
}
188173

189174
/*
@@ -215,8 +200,9 @@ rust_demangle_sym (char *sym)
215200
if (unescaped)
216201
*out++ = unescaped;
217202
else
218-
/* unexpected escape sequence, not looks_like_rust. */
219-
goto fail;
203+
/* unexpected escape sequence, skip the rest of this segment. */
204+
while (in < end && *in != ':')
205+
*out++ = *in++;
220206
}
221207
else if (*in == '_')
222208
{
@@ -248,14 +234,14 @@ rust_demangle_sym (char *sym)
248234
else if (*in == ':' || ISALNUM (*in))
249235
*out++ = *in++;
250236
else
251-
/* unexpected character in symbol, not looks_like_rust. */
252-
goto fail;
237+
{
238+
/* unexpected character in symbol, not rust_is_mangled. */
239+
*out++ = '?'; /* This is pretty lame, but it's hard to do better. */
240+
*out = '\0';
241+
return;
242+
}
253243
}
254-
goto done;
255244

256-
fail:
257-
*out++ = '?'; /* This is pretty lame, but it's hard to do better. */
258-
done:
259245
*out = '\0';
260246
}
261247

libiberty/testsuite/rust-demangle-expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ main::main::he714a2e23ed7db2g
4141
# $XX$ substitutions should not contain just numbers.
4242
--format=auto
4343
_ZN4main4$99$17he714a2e23ed7db23E
44-
main::$99$::he714a2e23ed7db23
44+
main::$99$
4545
# _ at start of path should be removed.
4646
# ".." translates to "::" "$GT$" to ">" and "$LT$" to "<".
4747
--format=rust

0 commit comments

Comments
 (0)