Fix inconsistent symbol mangling of integers constants with -Zverbose

The `PrettyPrinter` changes formatting of array size and integer
constants based on `-Zverbose`, so its implementation cannot be used in
legacy symbol mangling.
This commit is contained in:
Tomasz Miąsko 2022-02-25 00:00:00 +00:00
parent f6634cc3c2
commit 99a77798d3
3 changed files with 505 additions and 7 deletions

View File

@ -216,7 +216,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
Ok(self)
}
fn print_type(self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
match *ty.kind() {
// Print all nominal types as paths (unlike `pretty_print_type`).
ty::FnDef(def_id, substs)
@ -224,6 +224,24 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
| ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs })
| ty::Closure(def_id, substs)
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
// The `pretty_print_type` formatting of array size depends on
// -Zverbose flag, so we cannot reuse it here.
ty::Array(ty, size) => {
self.write_str("[")?;
self = self.print_type(ty)?;
self.write_str("; ")?;
if let Some(size) = size.val().try_to_bits(self.tcx().data_layout.pointer_size) {
write!(self, "{}", size)?
} else if let ty::ConstKind::Param(param) = size.val() {
self = param.print(self)?
} else {
self.write_str("_")?
}
self.write_str("]")?;
Ok(self)
}
_ => self.pretty_print_type(ty),
}
}
@ -245,12 +263,22 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
// only print integers
if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int { .. })) = ct.val() {
if ct.ty().is_integral() {
return self.pretty_print_const(ct, true);
match (ct.val(), ct.ty().kind()) {
(
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(scalar))),
ty::Int(_) | ty::Uint(_),
) => {
// The `pretty_print_const` formatting depends on -Zverbose
// flag, so we cannot reuse it here.
let signed = matches!(ct.ty().kind(), ty::Int(_));
write!(
self,
"{:#?}",
ty::ConstInt::new(scalar, signed, ct.ty().is_ptr_sized_integral())
)?;
}
_ => self.write_str("_")?,
}
self.write_str("_")?;
Ok(self)
}

View File

@ -1,7 +1,7 @@
// build-fail
// revisions: legacy
// revisions: legacy verbose-legacy
// compile-flags: --crate-name=a -C symbol-mangling-version=legacy -Z unstable-options
//
//[verbose-legacy]compile-flags: -Zverbose
// normalize-stderr-test: "h[[:xdigit:]]{16}" -> "h[HASH]"
#![feature(never_type)]

View File

@ -0,0 +1,470 @@
error: symbol-name(_ZN1a1b16Type$LT$bool$GT$17h[HASH]E)
--> $DIR/types.rs:13:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<bool>::h[HASH])
--> $DIR/types.rs:13:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<bool>)
--> $DIR/types.rs:13:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b16Type$LT$char$GT$17h[HASH]E)
--> $DIR/types.rs:19:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<char>::h[HASH])
--> $DIR/types.rs:19:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<char>)
--> $DIR/types.rs:19:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b14Type$LT$i8$GT$17h[HASH]E)
--> $DIR/types.rs:25:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<i8>::h[HASH])
--> $DIR/types.rs:25:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<i8>)
--> $DIR/types.rs:25:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$i16$GT$17h[HASH]E)
--> $DIR/types.rs:31:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<i16>::h[HASH])
--> $DIR/types.rs:31:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<i16>)
--> $DIR/types.rs:31:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$i32$GT$17h[HASH]E)
--> $DIR/types.rs:37:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<i32>::h[HASH])
--> $DIR/types.rs:37:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<i32>)
--> $DIR/types.rs:37:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$i64$GT$17h[HASH]E)
--> $DIR/types.rs:43:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<i64>::h[HASH])
--> $DIR/types.rs:43:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<i64>)
--> $DIR/types.rs:43:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b14Type$LT$u8$GT$17h[HASH]E)
--> $DIR/types.rs:49:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<u8>::h[HASH])
--> $DIR/types.rs:49:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<u8>)
--> $DIR/types.rs:49:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$u16$GT$17h[HASH]E)
--> $DIR/types.rs:55:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<u16>::h[HASH])
--> $DIR/types.rs:55:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<u16>)
--> $DIR/types.rs:55:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$u32$GT$17h[HASH]E)
--> $DIR/types.rs:61:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<u32>::h[HASH])
--> $DIR/types.rs:61:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<u32>)
--> $DIR/types.rs:61:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$u64$GT$17h[HASH]E)
--> $DIR/types.rs:67:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<u64>::h[HASH])
--> $DIR/types.rs:67:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<u64>)
--> $DIR/types.rs:67:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$f32$GT$17h[HASH]E)
--> $DIR/types.rs:73:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<f32>::h[HASH])
--> $DIR/types.rs:73:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<f32>)
--> $DIR/types.rs:73:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$f64$GT$17h[HASH]E)
--> $DIR/types.rs:79:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<f64>::h[HASH])
--> $DIR/types.rs:79:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<f64>)
--> $DIR/types.rs:79:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b15Type$LT$str$GT$17h[HASH]E)
--> $DIR/types.rs:85:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<str>::h[HASH])
--> $DIR/types.rs:85:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<str>)
--> $DIR/types.rs:85:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b17Type$LT$$u21$$GT$17h[HASH]E)
--> $DIR/types.rs:91:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<!>::h[HASH])
--> $DIR/types.rs:91:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<!>)
--> $DIR/types.rs:91:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b20Type$LT$$LP$$RP$$GT$17h[HASH]E)
--> $DIR/types.rs:97:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<()>::h[HASH])
--> $DIR/types.rs:97:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<()>)
--> $DIR/types.rs:97:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b25Type$LT$$LP$u8$C$$RP$$GT$17h[HASH]E)
--> $DIR/types.rs:103:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<(u8,)>::h[HASH])
--> $DIR/types.rs:103:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<(u8,)>)
--> $DIR/types.rs:103:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b28Type$LT$$LP$u8$C$u16$RP$$GT$17h[HASH]E)
--> $DIR/types.rs:109:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<(u8,u16)>::h[HASH])
--> $DIR/types.rs:109:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<(u8,u16)>)
--> $DIR/types.rs:109:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b34Type$LT$$LP$u8$C$u16$C$u32$RP$$GT$17h[HASH]E)
--> $DIR/types.rs:115:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<(u8,u16,u32)>::h[HASH])
--> $DIR/types.rs:115:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<(u8,u16,u32)>)
--> $DIR/types.rs:115:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b28Type$LT$$BP$const$u20$u8$GT$17h[HASH]E)
--> $DIR/types.rs:121:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<*const u8>::h[HASH])
--> $DIR/types.rs:121:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<*const u8>)
--> $DIR/types.rs:121:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b26Type$LT$$BP$mut$u20$u8$GT$17h[HASH]E)
--> $DIR/types.rs:127:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<*mut u8>::h[HASH])
--> $DIR/types.rs:127:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<*mut u8>)
--> $DIR/types.rs:127:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b19Type$LT$$RF$str$GT$17h[HASH]E)
--> $DIR/types.rs:133:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<&str>::h[HASH])
--> $DIR/types.rs:133:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<&str>)
--> $DIR/types.rs:133:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b27Type$LT$$RF$mut$u20$str$GT$17h[HASH]E)
--> $DIR/types.rs:139:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<&mut str>::h[HASH])
--> $DIR/types.rs:139:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<&mut str>)
--> $DIR/types.rs:139:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b35Type$LT$$u5b$u8$u3b$$u20$0$u5d$$GT$17h[HASH]E)
--> $DIR/types.rs:145:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<[u8; 0]>::h[HASH])
--> $DIR/types.rs:145:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<[u8; 0]>)
--> $DIR/types.rs:145:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b22Type$LT$fn$LP$$RP$$GT$17h[HASH]E)
--> $DIR/types.rs:151:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<fn()>::h[HASH])
--> $DIR/types.rs:151:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<fn()>)
--> $DIR/types.rs:151:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b60Type$LT$unsafe$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RP$$GT$17h[HASH]E)
--> $DIR/types.rs:157:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<unsafe extern "C" fn()>::h[HASH])
--> $DIR/types.rs:157:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<unsafe extern "C" fn()>)
--> $DIR/types.rs:157:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: symbol-name(_ZN1a1b34Type$LT$$u5b$T$u3b$$u20$N$u5d$$GT$17h[HASH]E)
--> $DIR/types.rs:163:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(a::b::Type<[T; N]>::h[HASH])
--> $DIR/types.rs:163:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(a::b::Type<[T; N]>)
--> $DIR/types.rs:163:5
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 78 previous errors