diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-06 17:01:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-06 17:01:49 +0000 |
commit | 0b0deb4ee9d2a4775b76c49dd1708c952406745d (patch) | |
tree | 9cd5c52d621fa0b99d42c1257cde20dbb5b64ac8 /gcc | |
parent | 69f6be3ee483c9895b4b5187a44b3e1c8be2ba63 (diff) | |
parent | bfb7ef7fc8244f9196c55202e4ae5fbbe1ebdd30 (diff) | |
download | gcc-0b0deb4ee9d2a4775b76c49dd1708c952406745d.zip gcc-0b0deb4ee9d2a4775b76c49dd1708c952406745d.tar.gz gcc-0b0deb4ee9d2a4775b76c49dd1708c952406745d.tar.bz2 |
Merge #847
847: HIR::ImplBlock items should mangle based from their canonical path's r=philberty a=philberty
Legacy mangling converts the '<', '>' from their canonical paths into '..'
this means we can simply reuse our normal mangle_item code for all types
of symbols. So we can now remove the mangle_impl_item code prior to having
the canonical path code in place.
Fixes #845
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 8 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-implitem.h | 3 | ||||
-rw-r--r-- | gcc/rust/backend/rust-mangle.cc | 68 | ||||
-rw-r--r-- | gcc/rust/backend/rust-mangle.h | 8 | ||||
-rw-r--r-- | gcc/testsuite/rust/execute/torture/issue-845.rs | 47 |
5 files changed, 53 insertions, 81 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 896d42e..43c23dd 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -310,14 +310,6 @@ public: return mangler.mangle_item (ty, path, mappings->get_current_crate_name ()); } - std::string mangle_impl_item (const TyTy::BaseType *self, - const TyTy::BaseType *ty, - const std::string &name) const - { - return mangler.mangle_impl_item (self, ty, name, - mappings->get_current_crate_name ()); - } - private: ::Backend *backend; Resolver::Resolver *resolver; diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h index 7b41226..1da607a 100644 --- a/gcc/rust/backend/rust-compile-implitem.h +++ b/gcc/rust/backend/rust-compile-implitem.h @@ -153,8 +153,7 @@ public: std::string ir_symbol_name = canonical_path->get () + fntype->subst_as_string (); - std::string asm_name - = ctx->mangle_impl_item (self, fntype, function.get_function_name ()); + std::string asm_name = ctx->mangle_item (fntype, *canonical_path); tree fndecl = ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name, diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc index d0fec0d..26c760e 100644 --- a/gcc/rust/backend/rust-mangle.cc +++ b/gcc/rust/backend/rust-mangle.cc @@ -31,6 +31,8 @@ legacy_mangle_name (const std::string &name) m = "$"; else if (c == '&') m = "RF"; + else if (c == '<' || c == '>') + m = ".."; else m.push_back (c); @@ -71,36 +73,6 @@ legacy_hash (const std::string &fingerprint) } static std::string -legacy_mangle_self (const TyTy::BaseType *self) -{ - if (self->get_kind () != TyTy::TypeKind::ADT) - return legacy_mangle_name (self->get_name ()); - - const TyTy::ADTType *s = static_cast<const TyTy::ADTType *> (self); - std::string buf = s->get_identifier (); - - if (s->has_subsititions_defined ()) - { - buf += kMangledSubstBegin; - - const std::vector<TyTy::SubstitutionParamMapping> ¶ms - = s->get_substs (); - for (size_t i = 0; i < params.size (); i++) - { - const TyTy::SubstitutionParamMapping &sub = params.at (i); - buf += sub.as_string (); - - if ((i + 1) < params.size ()) - buf += kMangledGenericDelim; - } - - buf += kMangledSubstEnd; - } - - return legacy_mangle_name (buf); -} - -static std::string v0_tuple_prefix (const TyTy::BaseType *ty) { if (ty->is_unit ()) @@ -255,19 +227,6 @@ legacy_mangle_item (const TyTy::BaseType *ty, + legacy_mangle_canonical_path (path) + hash_sig + kMangledSymbolDelim; } -// FIXME this is a wee bit broken -static std::string -legacy_mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty, - const std::string &name, const std::string &crate_name) -{ - const std::string hash = legacy_hash (ty->as_string ()); - const std::string hash_sig = legacy_mangle_name (hash); - - return kMangledSymbolPrefix + legacy_mangle_name (crate_name) - + legacy_mangle_self (self) + legacy_mangle_name (name) + hash_sig - + kMangledSymbolDelim; -} - static std::string v0_mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path, const std::string &crate_name) @@ -282,13 +241,6 @@ v0_mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path, gcc_unreachable (); } -static std::string -v0_mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty, - const std::string &name, const std::string &crate_name) -{ - gcc_unreachable (); -} - std::string Mangler::mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path, @@ -305,21 +257,5 @@ Mangler::mangle_item (const TyTy::BaseType *ty, } } -std::string -Mangler::mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty, - const std::string &name, - const std::string &crate_name) const -{ - switch (version) - { - case Mangler::MangleVersion::LEGACY: - return legacy_mangle_impl_item (self, ty, name, crate_name); - case Mangler::MangleVersion::V0: - return v0_mangle_impl_item (self, ty, name, crate_name); - default: - gcc_unreachable (); - } -} - } // namespace Compile } // namespace Rust diff --git a/gcc/rust/backend/rust-mangle.h b/gcc/rust/backend/rust-mangle.h index 9e77c54..0cc7f76 100644 --- a/gcc/rust/backend/rust-mangle.h +++ b/gcc/rust/backend/rust-mangle.h @@ -21,6 +21,7 @@ namespace Rust { namespace Compile { + class Mangler { public: @@ -36,11 +37,6 @@ public: const Resolver::CanonicalPath &path, const std::string &crate_name) const; - std::string mangle_impl_item (const TyTy::BaseType *self, - const TyTy::BaseType *ty, - const std::string &name, - const std::string &crate_name) const; - static void set_mangling (int frust_mangling_value) { version = static_cast<MangleVersion> (frust_mangling_value); @@ -49,6 +45,8 @@ public: private: static enum MangleVersion version; }; + } // namespace Compile } // namespace Rust + #endif // RUST_MANGLE_H diff --git a/gcc/testsuite/rust/execute/torture/issue-845.rs b/gcc/testsuite/rust/execute/torture/issue-845.rs new file mode 100644 index 0000000..4c689e3 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/issue-845.rs @@ -0,0 +1,47 @@ +// { dg-output "Foo::bar\n" } +// { dg-additional-options "-w" } +extern "C" { + fn printf(s: *const i8, ...); +} + +struct Foo {} + +trait Bar { + fn bar(&self) { + unsafe { + let _a = "Bar::bar\n\0"; + let _b = _a as *const str; + let _c = _b as *const i8; + printf(_c); + } + } +} + +impl Foo { + fn bar(&self) { + unsafe { + let _a = "Foo::bar\n\0"; + let _b = _a as *const str; + let _c = _b as *const i8; + printf(_c); + } + } +} + +impl Bar for Foo { + fn bar(&self) { + unsafe { + let _a = "<Bar as Foo>::bar\n\0"; + let _b = _a as *const str; + let _c = _b as *const i8; + printf(_c); + } + } +} + +pub fn main() -> i32 { + let mut f = Foo {}; + f.bar(); + + 0 +} |