aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-context.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-09-27 12:19:43 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-09-27 12:24:37 +0100
commit770a2449e8e3b7c9c8a9627ce5d57c3bcd99177c (patch)
tree45bae69df12f0122937373504701f25745cb70b2 /gcc/rust/backend/rust-compile-context.h
parent3a24dde2e7adec97243b95c79ea7877698f17c19 (diff)
downloadgcc-770a2449e8e3b7c9c8a9627ce5d57c3bcd99177c.zip
gcc-770a2449e8e3b7c9c8a9627ce5d57c3bcd99177c.tar.gz
gcc-770a2449e8e3b7c9c8a9627ce5d57c3bcd99177c.tar.bz2
Fix duplicated function generation on higher ranked trait bounds
Deuplicate function elimination can fail when we compile helpers during higher ranked trait bound monomorphization. This because the TyTy::BaseType info can be lost/reset during the compilation process. This adds a second mechanism to match based on the manged names which is a bit more reliable. This patch is required since the query based refactor of the type system so this issue was likely hidden to to using duplicated type info for higher ranked trait bounds.
Diffstat (limited to 'gcc/rust/backend/rust-compile-context.h')
-rw-r--r--gcc/rust/backend/rust-compile-context.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 096b65f..415b13e 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -148,7 +148,8 @@ public:
}
bool lookup_function_decl (HirId id, tree *fn, DefId dId = UNKNOWN_DEFID,
- const TyTy::BaseType *ref = nullptr)
+ const TyTy::BaseType *ref = nullptr,
+ const std::string &asm_name = std::string ())
{
// for for any monomorphized fns
if (ref != nullptr)
@@ -163,11 +164,29 @@ public:
{
const TyTy::BaseType *r = e.first;
tree f = e.second;
+
if (ref->is_equal (*r))
{
*fn = f;
return true;
}
+
+ if (DECL_ASSEMBLER_NAME_SET_P (f) && !asm_name.empty ())
+ {
+ tree raw = DECL_ASSEMBLER_NAME_RAW (f);
+ const char *rptr = IDENTIFIER_POINTER (raw);
+
+ bool lengths_match_p
+ = IDENTIFIER_LENGTH (raw) == asm_name.size ();
+ if (lengths_match_p
+ && strncmp (rptr, asm_name.c_str (),
+ IDENTIFIER_LENGTH (raw))
+ == 0)
+ {
+ *fn = f;
+ return true;
+ }
+ }
}
return false;
}