Skip to content

Commit 18464d3

Browse files
philbertyCohenArthur
authored andcommitted
gccrs: improve name mangling hash
We can endup with duplicate symbol names for different intrinsics with our current hash setup. This adds in the mappings and extra info to improve hash uniqueness. Addresses Rust-GCC#1895 gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (check_for_cached_intrinsic): simplify this cached intrinsic check * backend/rust-mangle.cc (legacy_mangle_item): use new interface * typecheck/rust-tyty.h: new managle helper Signed-off-by: Philip Herron <[email protected]>
1 parent 4459962 commit 18464d3

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

gcc/rust/backend/rust-compile-intrinsic.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,12 @@ Intrinsics::compile (TyTy::FnType *fntype)
242242
static bool
243243
check_for_cached_intrinsic (Context *ctx, TyTy::FnType *fntype, tree *lookup)
244244
{
245+
const Resolver::CanonicalPath &canonical_path = fntype->get_ident ().path;
246+
std::string asm_name = ctx->mangle_item (fntype, canonical_path);
245247
if (ctx->lookup_function_decl (fntype->get_ty_ref (), lookup,
246-
fntype->get_id (), fntype))
248+
fntype->get_id (), fntype, asm_name))
247249
{
248-
// Has this been added to the list? Then it must be finished
249-
if (ctx->function_completed (*lookup))
250-
{
251-
tree dummy = NULL_TREE;
252-
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
253-
ctx->insert_function_decl (fntype, *lookup);
254-
return true;
255-
}
250+
return true;
256251
}
257252

258253
return false;

gcc/rust/backend/rust-mangle.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static std::string
282282
legacy_mangle_item (const TyTy::BaseType *ty,
283283
const Resolver::CanonicalPath &path)
284284
{
285-
const std::string hash = legacy_hash (ty->as_string ());
285+
const std::string hash = legacy_hash (ty->mangle_string ());
286286
const std::string hash_sig = legacy_mangle_name (hash);
287287

288288
return kMangledSymbolPrefix + legacy_mangle_canonical_path (path) + hash_sig

gcc/rust/typecheck/rust-tyty.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ class BaseType : public TypeBoundsMappings
158158
bool has_subsititions_defined () const;
159159
bool needs_generic_substitutions () const;
160160

161+
std::string mangle_string () const
162+
{
163+
return TypeKindFormat::to_string (get_kind ()) + ":" + as_string () + ":"
164+
+ mappings_str () + ":" + bounds_as_string ();
165+
}
166+
161167
/* Returns a pointer to a clone of this. The caller is responsible for
162168
* releasing the memory of the returned ty. */
163169
virtual BaseType *clone () const = 0;

0 commit comments

Comments
 (0)