diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-05-23 11:03:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-23 11:03:46 +0000 |
commit | c7008d3e254786b5e752aa61e067f62c38042b81 (patch) | |
tree | 7c197b54d3e150c643b46ebfadb709ef83befa73 /gcc/rust/backend | |
parent | 9204e7a1ac617126b65c27668524aebf8f65f134 (diff) | |
parent | a647c005908d79bc6b50739c43b7ac105bc193a9 (diff) | |
download | gcc-c7008d3e254786b5e752aa61e067f62c38042b81.zip gcc-c7008d3e254786b5e752aa61e067f62c38042b81.tar.gz gcc-c7008d3e254786b5e752aa61e067f62c38042b81.tar.bz2 |
Merge #1266
1266: Make TyTy::BaseType::destructure recursive r=philberty a=philberty
In the case of Generic Associated Types we end up
placeholders->projections->generic-param->i32
This means we need to keep destructuring the TyTy object until we finally
get the real type at the end. In order to do this safely we need to ensure
we add in recursion limits and apply this where it matters such as
compiling types in general too.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-type.cc | 12 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-type.h | 7 |
2 files changed, 11 insertions, 8 deletions
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index 3874027..102bc0a 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -112,9 +112,15 @@ TyTyResolveCompile::visit (const TyTy::PlaceholderType &type) void TyTyResolveCompile::visit (const TyTy::ParamType ¶m) { - // FIXME make this reuse the same machinery from constexpr code - recursion_count++; - rust_assert (recursion_count < kDefaultRecusionLimit); + if (recurisve_ops++ >= rust_max_recursion_depth) + { + rust_error_at (Location (), + "%<recursion depth%> count exceeds limit of %i (use " + "%<frust-max-recursion-depth=%> to increase the limit)", + rust_max_recursion_depth); + translated = error_mark_node; + return; + } param.resolve ()->accept_vis (*this); } diff --git a/gcc/rust/backend/rust-compile-type.h b/gcc/rust/backend/rust-compile-type.h index 3e1f903..262b8fc 100644 --- a/gcc/rust/backend/rust-compile-type.h +++ b/gcc/rust/backend/rust-compile-type.h @@ -63,16 +63,13 @@ public: private: TyTyResolveCompile (Context *ctx, bool trait_object_mode) : ctx (ctx), trait_object_mode (trait_object_mode), - translated (error_mark_node), recursion_count (0) + translated (error_mark_node), recurisve_ops (0) {} Context *ctx; bool trait_object_mode; tree translated; - - // FIXME this needs to be derived from the gcc config option - size_t recursion_count; - static const size_t kDefaultRecusionLimit = 5; + int recurisve_ops; }; } // namespace Compile |