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

Trieste segfaults, when no passes are defined #133

Open
xFrednet opened this issue Aug 17, 2024 · 1 comment
Open

Trieste segfaults, when no passes are defined #133

xFrednet opened this issue Aug 17, 2024 · 1 comment

Comments

@xFrednet
Copy link

xFrednet commented Aug 17, 2024

I've been working thought the infix tutorial. After prototyping the parser, I wanted to try it out, but the program segfaults. The problem only went away after I defined a pass.

Backtrace from GDB
(gdb) run
Starting program: <path>/build/<output-bin> 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data (this=0xffffffffffffffe0) at /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/basic_string.h:195
195           { return _M_dataplus._M_p; }
(gdb) backtrace
#0  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data (this=0xffffffffffffffe0) at /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/basic_string.h:195
#1  0x00005555556c3b99 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (this=0x7fffffffd2c0, __str=<error reading variable: Cannot access memory at address 0xffffffffffffffe8>)
    at /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/basic_string.h:459
#2  0x00005555556c4a8a in trieste::Driver::run (this=0x7fffffffd858, argc=1, argv=0x7fffffffdee8) at _deps/trieste-src/include/trieste/driver.h:59
#3  0x00005555556beb7b in main (argc=1, argv=0x7fffffffdee8) at <path>/src/main.cc:7

I'm guessing that the issue comes from the Drivers CLI construction here:

std::vector<std::string> pass_names = reader.pass_names();
std::string end_pass = pass_names.back();
build->add_option("-p,--pass", end_pass, "Run up to this pass.")
->transform(CLI::IsMember(pass_names));

The code just calls pass_names.back(); and the documentation states:

Calling back() on an empty container causes undefined behavior.

~ https://en.cppreference.com/w/cpp/container/vector/back

I'd be happy to send a fix if the intended behavior is defined. The easiest might be to remove that argument, if no passes have been defined.


I haven't constructed a minimum reproducible example. Just removing the passes from the infix example should result in the same error.

@fhackett
Copy link
Contributor

I think a few things assume pass count >0, or even >1.

In my opinion, a simple fix is to throw an exception if this happens (that explains the assumption, of course). More fundamentally, one could ask what an empty pass list means and implement that, but I imagine it is a more subtle change.

For instance, I remember having an issue with the fuzzer setup where it would do nothing if there was only one pass.

These are all cases that haven't got good test coverage, on account of all the Trieste users having more than 0 or 1 passes, so I'm sure that contributing a couple of tests + proposed fixes for discussion would be welcome.

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

No branches or pull requests

2 participants