diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-07-05 12:42:31 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-07-05 12:48:11 +0100 |
commit | dc5e01832772304e2a988406e78d3d83fe83f278 (patch) | |
tree | a7b2fca46909c8d6c44d3fba5a77b58d10544ef7 | |
parent | 210ae4f7b0fea9671482b8f01354fd5b9274f878 (diff) | |
download | gcc-dc5e01832772304e2a988406e78d3d83fe83f278.zip gcc-dc5e01832772304e2a988406e78d3d83fe83f278.tar.gz gcc-dc5e01832772304e2a988406e78d3d83fe83f278.tar.bz2 |
Fix bad naming of primitive types such as u64 which ended up as usize
There was a bad port over of the gccgo named_type implementation to try
be simple but this ended up overwriting the names of other primitive types
leading to confusing gimple debug sessions.
In debugging this I have added a set of ids which are the builtin primitive
types ids and we assert that this range of ids will never be overriten by
other types during compilation.
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 9 | ||||
-rw-r--r-- | gcc/rust/rust-gcc.cc | 24 |
2 files changed, 26 insertions, 7 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index e0c9352..5d19099 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -58,8 +58,9 @@ public: TyTy::BaseType *lookup; rust_assert (tyctx->lookup_type (ref, &lookup)); - auto compiled = TyTyCompile::compile (backend, lookup); - compiled_type_map[ref] = compiled; + Btype *compiled = TyTyCompile::compile (backend, lookup); + compiled_type_map.insert (std::pair<HirId, Btype *> (ref, compiled)); + builtin_range.insert (ref); } } @@ -94,7 +95,8 @@ public: void insert_compiled_type (HirId id, ::Btype *type, const TyTy::BaseType *ref = nullptr) { - compiled_type_map[id] = type; + rust_assert (builtin_range.find (id) == builtin_range.end ()); + compiled_type_map.insert (std::pair<HirId, Btype *> (id, type)); if (ref != nullptr) { std::pair<HirId, ::Btype *> elem (id, type); @@ -297,6 +299,7 @@ private: Resolver::TypeCheckContext *tyctx; Analysis::Mappings *mappings; ConstFold::Context *const_ctx; + std::set<HirId> builtin_range; // state std::vector<fncontext> fn_stack; diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index 794660e..74a8b52 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -1306,11 +1306,27 @@ Gcc_backend::named_type (const std::string &name, Btype *btype, if (type == error_mark_node) return this->error_type (); + // The middle-end expects a basic type to have a name. In Rust every + // basic type will have a name. The first time we see a basic type, + // give it whatever Rust name we have at this point. + if (TYPE_NAME (type) == NULL_TREE + && location.gcc_location () == BUILTINS_LOCATION + && (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == REAL_TYPE + || TREE_CODE (type) == COMPLEX_TYPE + || TREE_CODE (type) == BOOLEAN_TYPE)) + { + tree decl = build_decl (BUILTINS_LOCATION, TYPE_DECL, + get_identifier_from_string (name), type); + TYPE_NAME (type) = decl; + return this->make_type (type); + } + + tree copy = build_variant_type_copy (type); tree decl = build_decl (location.gcc_location (), TYPE_DECL, - get_identifier_from_string (name), type); - - TYPE_NAME (type) = decl; - return this->make_type (type); + get_identifier_from_string (name), copy); + DECL_ORIGINAL_TYPE (decl) = type; + TYPE_NAME (copy) = decl; + return this->make_type (copy); } // Return a pointer type used as a marker for a circular type. |