Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when binding richloc to paser errors #2566

Open
MahadMuhammad opened this issue Aug 17, 2023 · 2 comments
Open

ICE when binding richloc to paser errors #2566

MahadMuhammad opened this issue Aug 17, 2023 · 2 comments
Labels

Comments

@MahadMuhammad
Copy link
Contributor

MahadMuhammad commented Aug 17, 2023

Fixing this issue, improve this

I tried binding rich location to parser errors, but it emits ICE

This issue is becuase this STATICALLY_ALLOCATED_RANGES is set to 3

static const int STATICALLY_ALLOCATED_RANGES = 3;
protected:
line_maps *m_line_table;
semi_embedded_vec <location_range, STATICALLY_ALLOCATED_RANGES> m_ranges;

And then it's break's on this assertion

template <typename T, int NUM_EMBEDDED>
const T&
semi_embedded_vec<T, NUM_EMBEDDED>::operator[] (int idx) const
{
linemap_assert (idx < m_num);
if (idx < NUM_EMBEDDED)
return m_embedded[idx];
else
{
linemap_assert (m_extra != NULL);
return m_extra[idx - NUM_EMBEDDED];
}
}

Due, to this assertion, it is difficult to bind rich_location with parser errors.

Backtrace

➜  gccrs-build gcc/crab1 /home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/auto_trait_invalid.rs

The range is 1  // This line was printed by me, printf("\n The range is %d\n", richloc.get_num_locations ());

crab1: internal compiler error: in operator[], at libcpp/include/line-map.h:1438
0x22e242a semi_embedded_vec<location_range, 3>::operator[](int) const
  ../../gccrs/libcpp/include/line-map.h:1438
0x22e242a rich_location::get_range(unsigned int) const
  ../../gccrs/libcpp/line-map.cc:2154
0x22e242a rich_location::get_loc(unsigned int) const
  ../../gccrs/libcpp/line-map.cc:2145
0x12b418d diagnostic_location(diagnostic_info const*, int)
  ../../gccrs/gcc/diagnostic.h:555
0x12b418d diagnostic_report_current_function(diagnostic_context*, diagnostic_info*)
  ../../gccrs/gcc/tree-diagnostic.cc:40
0x12b41f4 default_tree_diagnostic_starter
  ../../gccrs/gcc/tree-diagnostic.cc:49
0x2289a13 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
  ../../gccrs/gcc/diagnostic.cc:1593
0x228a18a diagnostic_impl
  ../../gccrs/gcc/diagnostic.cc:1756
0x228d16a error_meta(rich_location*, diagnostic_metadata const&, char const*, ...)
  ../../gccrs/gcc/diagnostic.cc:2108
0x9e1769 rust_be_error_at(rich_location*, ErrorCode, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
  ../../gccrs/gcc/rust/rust-diagnostics.cc:286
0x9e27ef rust_error_at(rich_location*, ErrorCode, char const*, ...)
  ../../gccrs/gcc/rust/rust-diagnostics.cc:296
0xac6bde Rust::Error::emit() const
  ../../gccrs/gcc/rust/rust-diagnostics.h:285
0xac6bde Rust::Parser<Rust::Lexer>::parse_crate()
  ../../gccrs/gcc/rust/parse/rust-parse-impl.h:448
0xac1e83 Rust::Session::compile_crate(char const*)
  ../../gccrs/gcc/rust/rust-session-manager.cc:522
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Meta

  • What version of Rust GCC were you using, git sha efa3041

This is the code, I experimented MahadMuhammad@9b911fd

@CohenArthur
Copy link
Member

what code did you try that caused the ICE exactly?

@MahadMuhammad
Copy link
Contributor Author

I tried this code

// #![feature(auto_traits)] // not present in Rust 1.49 yet

#![feature(optin_builtin_traits)]

unsafe auto trait Invalid { // { dg-error "associated items are forbidden within auto traits" }
    fn foo(); // { dg-message "remove this item" }

    fn bar() {} // { dg-message "remove this item" }

    type Foo; // { dg-message "remove this item" }

    const FOO: i32; // { dg-message "remove this item" }

    const BAR: i32 = 15; // { dg-message "remove this item" }
}
// { dg-error "failed to parse item in crate" "" {target *-*-* } .+1 }
Backtrace

➜  gccrs-build gcc/crab1 /home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/auto_trait_invalid.rs

The range is 1  // This line was printed by me, printf("\n The range is %d\n", richloc.get_num_locations ());

crab1: internal compiler error: in operator[], at libcpp/include/line-map.h:1438
0x22e242a semi_embedded_vec<location_range, 3>::operator[](int) const
  ../../gccrs/libcpp/include/line-map.h:1438
0x22e242a rich_location::get_range(unsigned int) const
  ../../gccrs/libcpp/line-map.cc:2154
0x22e242a rich_location::get_loc(unsigned int) const
  ../../gccrs/libcpp/line-map.cc:2145
0x12b418d diagnostic_location(diagnostic_info const*, int)
  ../../gccrs/gcc/diagnostic.h:555
0x12b418d diagnostic_report_current_function(diagnostic_context*, diagnostic_info*)
  ../../gccrs/gcc/tree-diagnostic.cc:40
0x12b41f4 default_tree_diagnostic_starter
  ../../gccrs/gcc/tree-diagnostic.cc:49
0x2289a13 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
  ../../gccrs/gcc/diagnostic.cc:1593
0x228a18a diagnostic_impl
  ../../gccrs/gcc/diagnostic.cc:1756
0x228d16a error_meta(rich_location*, diagnostic_metadata const&, char const*, ...)
  ../../gccrs/gcc/diagnostic.cc:2108
0x9e1769 rust_be_error_at(rich_location*, ErrorCode, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
  ../../gccrs/gcc/rust/rust-diagnostics.cc:286
0x9e27ef rust_error_at(rich_location*, ErrorCode, char const*, ...)
  ../../gccrs/gcc/rust/rust-diagnostics.cc:296
0xac6bde Rust::Error::emit() const
  ../../gccrs/gcc/rust/rust-diagnostics.h:285
0xac6bde Rust::Parser<Rust::Lexer>::parse_crate()
  ../../gccrs/gcc/rust/parse/rust-parse-impl.h:448
0xac1e83 Rust::Session:with backtrace::compile_crate(char const*)
  ../../gccrs/gcwith backtrace:c/rust/rust-session-manager.cc:522
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

And this code compiles successfully, instead of emitting error:

If we use simple location instead of these, then it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants