Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.4k stars 155 forks source link

Invalid use of .front() #2417

Open dkm opened 1 year ago

dkm commented 1 year ago

In https://github.com/Rust-GCC/gccrs/blob/b75357f4a1835dcd288df67402340b4cb6b96c12/gcc/rust/typecheck/rust-tyty-bounds.cc#L317

.front() is called on an empty list. Enabling libstdc++ assertion gives:

 0x3bb69da crash_signal
  66   │     ../../gcc/toplev.cc:314
  67   │ 0x7f769b0c1f8f ???
  68   │     ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
  69   │ 0x7f769b110ccc __pthread_kill_implementation
  70   │     ./nptl/pthread_kill.c:44
  71   │ 0x7f769b0c1ef1 __GI_raise
  72   │     ../sysdeps/posix/raise.c:26
  73   │ 0x7f769b0ac471 __GI_abort
  74   │     ./stdlib/abort.c:79
  75   │ 0x22375a4 std::vector<Rust::TyTy::SubstitutionParamMapping, std::allocator<Rust::TyTy::SubstitutionParamMapping> >::front()
  76   │     /usr/include/c++/12/bits/stl_vector.h:1206
  77   │ 0x224ecec Rust::TyTy::TypeBoundPredicate::TypeBoundPredicate(Rust::DefId, std::vector<Rust::TyTy::SubstitutionParamMapping, std::allocator<Rust::TyTy::SubstitutionPa
       │ ramMapping> >, unsigned int)
  78   │     ../../gcc/rust/typecheck/rust-tyty-bounds.cc:317
dkm commented 1 year ago

Removing the dummy mapping doesn't break any test, but will let @philberty decide if this is a safe fix or not.

philberty commented 1 year ago

Ohh good find... do you have a test case for this one?

Every trait is meant to have an implicit Self type parameter so we should really at bare minimum assert that:

get_substs is not empty and see if that passes the testsuite.