diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-08-26 09:42:08 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-08-26 10:00:48 +0100 |
commit | 8c6a2f1dbf8f9fba942e7be4b566f105bb21f224 (patch) | |
tree | 443a619f141adaf6777eee737055c942837f48fb /gcc | |
parent | 40042ce11fc5d7f62e31be99e82bf6a0db83234a (diff) | |
download | gcc-8c6a2f1dbf8f9fba942e7be4b566f105bb21f224.zip gcc-8c6a2f1dbf8f9fba942e7be4b566f105bb21f224.tar.gz gcc-8c6a2f1dbf8f9fba942e7be4b566f105bb21f224.tar.bz2 |
Fix issue with mangled name on function items with substitutions
Rust legacy name mangling does not contain the substitutions as part of
its mangled name for Item's. Rust avoids duplicate symbol collisions with
the legacy mangling scheme, but including a 128bit hash at the end of the
symbol, which is made up with metadata and in this case the mangled symbol
contains a hash of the type which this function is.
Fixes #647
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 11 | ||||
-rw-r--r-- | gcc/testsuite/rust/execute/torture/issue-647.rs | 33 |
2 files changed, 34 insertions, 10 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index eb7d9ef..1871d10 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -199,16 +199,7 @@ public: // yet if (!is_main_fn) { - std::string substs_str = fntype->subst_as_string (); - - Resolver::CanonicalPath mangle_me - = substs_str.empty () - ? *canonical_path - : canonical_path->append ( - Resolver::CanonicalPath::new_seg (0, - fntype->subst_as_string ())); - - asm_name = ctx->mangle_item (fntype, mangle_me); + asm_name = ctx->mangle_item (fntype, *canonical_path); } Bfunction *fndecl diff --git a/gcc/testsuite/rust/execute/torture/issue-647.rs b/gcc/testsuite/rust/execute/torture/issue-647.rs new file mode 100644 index 0000000..3f427cc --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/issue-647.rs @@ -0,0 +1,33 @@ +/* { dg-output "Hello World 123\n" }*/ +extern "C" { + fn printf(s: *const i8, ...); +} + +struct Foo<T>(T); + +struct Bar<T> { + a: Foo<T>, + b: bool, + // { dg-warning "field is never read" "" { target *-*-* } .-1 } +} + +fn test<T>(a: Bar<T>) -> Foo<T> { + a.a +} + +fn main() -> i32 { + let a: Bar<i32> = Bar::<i32> { + a: Foo::<i32>(123), + b: true, + }; + let result: Foo<i32> = test(a); + + unsafe { + let a = "Hello World %i\n"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, result.0); + } + 0 +} |