rustc:🔙🔗 redo symbol mangling
Handle more characters that appear in types, most notably <>): were missing. Also the new scheme takes care that no two different input strings result in the same mangled string, which was not the case before. Fixes #6921
This commit is contained in:
parent
de3000af8f
commit
eb62781720
@ -633,26 +633,37 @@ pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
|
|||||||
|
|
||||||
// Name sanitation. LLVM will happily accept identifiers with weird names, but
|
// Name sanitation. LLVM will happily accept identifiers with weird names, but
|
||||||
// gas doesn't!
|
// gas doesn't!
|
||||||
|
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
|
||||||
pub fn sanitize(s: &str) -> ~str {
|
pub fn sanitize(s: &str) -> ~str {
|
||||||
let mut result = ~"";
|
let mut result = ~"";
|
||||||
for str::each_char(s) |c| {
|
for str::each_char(s) |c| {
|
||||||
match c {
|
match c {
|
||||||
'@' => result += "_sbox_",
|
// Escape these with $ sequences
|
||||||
'~' => result += "_ubox_",
|
'@' => result += "$SP$",
|
||||||
'*' => result += "_ptr_",
|
'~' => result += "$UP$",
|
||||||
'&' => result += "_ref_",
|
'*' => result += "$RP$",
|
||||||
',' => result += "_",
|
'&' => result += "$BP$",
|
||||||
|
'<' => result += "$LT$",
|
||||||
|
'>' => result += "$GT$",
|
||||||
|
'(' => result += "$LP$",
|
||||||
|
')' => result += "$RP$",
|
||||||
|
',' => result += "$C$",
|
||||||
|
|
||||||
'{' | '(' => result += "_of_",
|
// '.' doesn't occur in types and functions, so reuse it
|
||||||
'a' .. 'z'
|
// for ':'
|
||||||
| 'A' .. 'Z'
|
':' => result.push_char('.'),
|
||||||
| '0' .. '9'
|
|
||||||
| '_' => result.push_char(c),
|
// These are legal symbols
|
||||||
_ => {
|
'a' .. 'z'
|
||||||
if c > 'z' && char::is_XID_continue(c) {
|
| 'A' .. 'Z'
|
||||||
result.push_char(c);
|
| '0' .. '9'
|
||||||
|
| '_' => result.push_char(c),
|
||||||
|
|
||||||
|
_ => {
|
||||||
|
if c > 'z' && char::is_XID_continue(c) {
|
||||||
|
result.push_char(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user