diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-07-06 09:26:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 09:26:19 +0000 |
commit | 3670b0ef05041b8a1defb755804ef36e029d20db (patch) | |
tree | 8b14fea7a5b5b7b69aa7572bcc59e155303ae17b /gcc | |
parent | 32c9b09fdb5470dda05375878032c9c7d1fd91f1 (diff) | |
parent | dc5e01832772304e2a988406e78d3d83fe83f278 (diff) | |
download | gcc-3670b0ef05041b8a1defb755804ef36e029d20db.zip gcc-3670b0ef05041b8a1defb755804ef36e029d20db.tar.gz gcc-3670b0ef05041b8a1defb755804ef36e029d20db.tar.bz2 |
Merge #548
548: Fix bad naming of primitive types such as u64 which ended up as usize r=philberty a=philberty
In #547 it was found that u64's ended up as usize in gimple which confuses
debugging sessions. This take the original implementation of named type
from gccgo showing it was the TYPE_NAME tree getting confused.
Addresses #547
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-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. |