Re: [PATCH] Suppress warning in rust-ast-lower-type.h ASTLowerGenericParam.visit.

2021-06-29 Thread Mark Wielaard
Hi Marc,

On Tue, Jun 29, 2021 at 08:28:51AM +0200, Marc wrote:
> Mark Wielaard  writes:
> > I just tried to make LifetimeType an enum class and that doesn't help.
> > So I was wrong. I don't know why the compiler doesn't see this? It
> > should know since if not all switch cases were covered, -Wswitch
> > (enabled by -Wall) gives us a warning... So, I don't fully understand
> > why gcc needs the default gcc_unreachable case. It is what is used in
> > the rest of the code though.
> 
> I thought maybe that's a C++ vs C diff, or something caused by the
> Lifetime being returned by a function call, but I can't reproduce it, so
> that must be something else:
> 
> https://godbolt.org/z/sjbcWEqdj

Try using the result of the function and using -O2

  enum LifetimeType
  {
NAMED,   // corresponds to LIFETIME_OR_LABEL
STATIC,  // corresponds to 'static
WILDCARD // corresponds to '_
  };

 int g(int i);

 LifetimeType toto();
  int t ()  {
  int t;
  switch(toto()){
  case NAMED:
  t=4;
  break;
  case STATIC:
  t=5;
  break;
  case WILDCARD:
  t=8;
  break;
  }
  return g(t);
  }

gcc -O2 -Wall

: In function 'int t()':
:24:15: warning: 't' may be used uninitialized in this function 
[-Wmaybe-uninitialized]
   24 |   return g(t);
  |  ~^~~

> Anyway, Philipp wants to have these enum shared between AST and HIR, so
> this kind of 'if(AST::Foo) t=HIR::Foo' can be removed.

That might be a good idea if the LifetimeType has the same values and
semantics between AST and HIR.

But till that happend I think it is a good idea to suppress warnings like this.

Cheers,

Mark

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[PATCH 2/2] Remove unused have_more_segments from TypeCheckExpr::resolve_root_path

2021-06-29 Thread Mark Wielaard
It isn't necessary to know whether there are more segments while
iteration through the expression segements.
---
 gcc/rust/typecheck/rust-hir-type-check-expr.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h 
b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index e06b10d358a..327a9a06df7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -1121,7 +1121,6 @@ private:
 for (size_t i = 0; i < expr.get_num_segments (); i++)
   {
HIR::PathExprSegment &seg = expr.get_segments ().at (i);
-   bool have_more_segments = i < expr.get_num_segments ();
bool is_root = *offset == 0;
NodeId ast_node_id = seg.get_mappings ().get_nodeid ();
 
-- 
2.32.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[PATCH 1/2] Remove unused default_ty_param from TypeResolveGenericParam::visit

2021-06-29 Thread Mark Wielaard
The default_ty_param was set, but not used. We do need to call 
TypeCheckType::Resolve
on the default param, but don't need the result.
---
 gcc/rust/typecheck/rust-hir-type-check-type.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h 
b/gcc/rust/typecheck/rust-hir-type-check-type.h
index b4baccf4299..6081ec549ce 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.h
@@ -255,11 +255,9 @@ public:
 
   void visit (HIR::TypeParam ¶m) override
   {
-TyTy::BaseType *default_ty_param = nullptr;
 if (param.has_type ())
-  {
-   default_ty_param = TypeCheckType::Resolve (param.get_type ().get ());
-  }
+  TypeCheckType::Resolve (param.get_type ().get ());
+
 resolved = new TyTy::ParamType (param.get_type_representation (),
param.get_mappings ().get_hirid (), param);
   }
-- 
2.32.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


Re: [PATCH 2/2] Remove unused have_more_segments from TypeCheckExpr::resolve_root_path

2021-06-29 Thread Marc via Gcc-rust
Mark Wielaard  writes:

> It isn't necessary to know whether there are more segments while
> iteration through the expression segements.

Both patches in GH: https://github.com/Rust-GCC/gccrs/pull/537/commits

Fixed a small typo in the commit message while creating the PR :)

Marc
-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust