marxin / cvise

Super-parallel Python port of the C-Reduce
Other
219 stars 25 forks source link

Infinite loop in clang_delta replace-function-def-with-decl #107

Closed avikivity closed 1 year ago

avikivity commented 1 year ago

cvise with the attached file (1997a703cdc1a1f9a5ca9c99cfa6536ae55186a6, built against LLVM 15) hangs in clang_delta.

Command line:

/usr/local/libexec/cvise/clang_delta --query-instances=replace-function-def-with-decl --std=c++20 /home/avi/scylla/bad.cc

https://scratch.scylladb.com/bad.cc

marxin commented 1 year ago

Thanks for the report. I can confirm that. Btw. is there a compiler that accepts the code without a compilation error?

marxin commented 1 year ago

Or can you share steps on how did you create the file?

avikivity commented 1 year ago

gcc ought to accept it without errors, but it ICEs (this is why I'm using cvise). clang won't accept the file as-is, since it was preprocessed with gcc. The file itself is part of a much larger project, it builds regularly with clang, I'm increasing its compatiblity with gcc and reporting gcc bugs as I go.

The project is https://github.com/scylladb/scylladb, the file is cql3/statements/select_statement.cc (but in a different branch that has gcc fixes - https://github.com/scylladb/scylladb/pull/13243)

To create the file, I tried to compile it with gcc, then adjusted the compile command line to preprocess instead of compile.

marxin commented 1 year ago

gcc ought to accept it without errors, but it ICEs (this is why I'm using cvise). clang won't accept the file as-is, since it was preprocessed with gcc. The file itself is part of a much larger project, it builds regularly with clang, I'm increasing its compatiblity with gcc and reporting gcc bugs as I go.

Ohh, cool, you're trying to use GCC instead of Clang, I do support that ;) Anyway, please send me here the full command line you use for gcc-13 and the ICE you face. I can help you with that.

marxin commented 1 year ago

and please show me gcc --version which would tell a revision you're using.

avikivity commented 1 year ago

We can move to the gcc bugzilla if you prefer.

Here's my interestingness test (which shows the command line):

#!/bin/bash

/home/avi/gcc.coroutines/bin/g++ -w   -march=westmere   --std=gnu++20  -c -o /dev/null bad.cc > error.log 2>&1

require() {
    grep -q "$1" error.log || exit 1
}

trap 'rm error.log' EXIT

require 'internal compiler error: Segmentation fault'
require build_special_member_call
require maybe_promote_temps
require await_statement_walker

exit 0

(westmere is due to the project as a whole requiring crc32c and pclmul, it's not relevant to this translation unit)

$ ~/gcc.coroutines/bin/g++ --version
g++ (GCC) 13.0.1 20230319 (experimental)
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc-mirror/gcc@8804eb0b880f81998fca6f77abdd01e124e565b7

marxin commented 1 year ago

Good, I can reproduce it and I'm going to move it to GCC bugzilla..

avikivity commented 1 year ago
bad.cc: In instantiation of ‘cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::query_processor&, std::vector<cql3::statements::select_statement::primary_key>&&, service::query_state&, const cql3::query_options&, gc_clock::time_point, seastar::lw_shared_ptr<const service::pager::paging_state>) const::_ZNK4cql310statements30indexed_table_select_statement21do_execute_base_queryERNS_15query_processorEOSt6vectorINS0_16select_statement11primary_keyESaIS6_EERN7service11query_stateERKNS_13query_optionsENSt6chrono10time_pointI8gc_clockNSG_8durationIlSt5ratioILl1ELl1EEEEEEN7seastar13lw_shared_ptrIKNSA_5pager12paging_stateEEE.Frame*)::<lambda(auto:351&)> [with auto:351 = cql3::statements::select_statement::primary_key]’:
bad.cc:15962:36:   required from ‘constexpr _Res std::__invoke_impl(__invoke_other, _Fn&&, _Args&& ...) [with _Res = seastar::future<boost::outcome_v2::basic_result<seastar::foreign_ptr<seastar::lw_shared_ptr<query::result> >, utils::exception_container<exceptions::mutation_write_timeout_exception, exceptions::read_timeout_exception, exceptions::read_failure_exception, exceptions::rate_limit_exception>, utils::exception_container_throw_policy> >; _Fn = cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::query_processor&, std::vector<cql3::statements::select_statement::primary_key>&&, service::query_state&, const cql3::query_options&, gc_clock::time_point, seastar::lw_shared_ptr<const service::pager::paging_state>) const::_ZNK4cql310statements30indexed_table_select_statement21do_execute_base_queryERNS_15query_processorEOSt6vectorINS0_16select_statement11primary_keyESaIS6_EERN7service11query_stateERKNS_13query_optionsENSt6chrono10time_pointI8gc_clockNSG_8durationIlSt5ratioILl1ELl1EEEEEEN7seastar13lw_shared_ptrIKNSA_5pager12paging_stateEEE.Frame*)::<lambda(auto:351&)>&; _Args = {cql3::statements::select_statement::primary_key&}]’
bad.cc:15991:40:   required from ‘constexpr typename std::__invoke_result<_Functor, _ArgTypes>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::query_processor&, std::vector<cql3::statements::select_statement::primary_key>&&, service::query_state&, const cql3::query_options&, gc_clock::time_point, seastar::lw_shared_ptr<const service::pager::paging_state>) const::_ZNK4cql310statements30indexed_table_select_statement21do_execute_base_queryERNS_15query_processorEOSt6vectorINS0_16select_statement11primary_keyESaIS6_EERN7service11query_stateERKNS_13query_optionsENSt6chrono10time_pointI8gc_clockNSG_8durationIlSt5ratioILl1ELl1EEEEEEN7seastar13lw_shared_ptrIKNSA_5pager12paging_stateEEE.Frame*)::<lambda(auto:351&)>&; _Args = {cql3::statements::select_statement::primary_key&}; typename __invoke_result<_Functor, _ArgTypes>::type = seastar::future<boost::outcome_v2::basic_result<seastar::foreign_ptr<seastar::lw_shared_ptr<query::result> >, utils::exception_container<exceptions::mutation_write_timeout_exception, exceptions::read_timeout_exception, exceptions::read_failure_exception, exceptions::rate_limit_exception>, utils::exception_container_throw_policy> >]’
bad.cc:47571:27:   required from ‘constexpr std::invoke_result_t<_Fn, _Args ...> std::invoke(_Callable&&, _Args&& ...) [with _Callable = cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::query_processor&, std::vector<cql3::statements::select_statement::primary_key>&&, service::query_state&, const cql3::query_options&, gc_clock::time_point, seastar::lw_shared_ptr<const service::pager::paging_state>) const::_ZNK4cql310statements30indexed_table_select_statement21do_execute_base_queryERNS_15query_processorEOSt6vectorINS0_16select_statement11primary_keyESaIS6_EERN7service11query_stateERKNS_13query_optionsENSt6chrono10time_pointI8gc_clockNSG_8durationIlSt5ratioILl1ELl1EEEEEEN7seastar13lw_shared_ptrIKNSA_5pager12paging_stateEEE.Frame*)::<lambda(auto:351&)>&; _Args = {cql3::statements::select_statement::primary_key&}; invoke_result_t<_Fn, _Args ...> = seastar::future<boost::outcome_v2::basic_result<seastar::foreign_ptr<seastar::lw_shared_ptr<query::result> >, utils::exception_container<exceptions::mutation_write_timeout_exception, exceptions::read_timeout_exception, exceptions::read_failure_exception, exceptions::rate_limit_exception>, utils::exception_container_throw_policy> >]’
bad.cc:234465:27:   required from ‘decltype(auto) seastar::coroutine::lambda<Func>::operator()(Args&& ...) const [with Args = {cql3::statements::select_statement::primary_key&}; Func = cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::query_processor&, std::vector<cql3::statements::select_statement::primary_key>&&, service::query_state&, const cql3::query_options&, gc_clock::time_point, seastar::lw_shared_ptr<const service::pager::paging_state>) const::_ZNK4cql310statements30indexed_table_select_statement21do_execute_base_queryERNS_15query_processorEOSt6vectorINS0_16select_statement11primary_keyESaIS6_EERN7service11query_stateERKNS_13query_optionsENSt6chrono10time_pointI8gc_clockNSG_8durationIlSt5ratioILl1ELl1EEEEEEN7seastar13lw_shared_ptrIKNSA_5pager12paging_stateEEE.Frame*)::<lambda(auto:351&)>]’
bad.cc:310499:13:   required by substitution of ‘template<class Iterator, class Mapper, class Reducer>  requires requires(Iterator i, Mapper mapper, Reducer reduce) {*i++;{i != i} -> decltype(auto) [requires std::convertible_to<<placeholder>, bool>];{mapper(*i)} -> decltype(auto) [requires utils::ExceptionContainerResultFuture<<placeholder>, >];{seastar::futurize_invoke(reduce, seastar::futurize_invoke(mapper, *i).get0().value())} -> decltype(auto) [requires std::same_as<<placeholder>, seastar::future<void> >];} auto utils::result_map_reduce(Iterator, Iterator, Mapper&&, Reducer&&) [with Iterator = __gnu_cxx::__normal_iterator<cql3::statements::select_statement::primary_key*, std::vector<cql3::statements::select_statement::primary_key> >; Mapper = seastar::coroutine::lambda<cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::statements::indexed_table_select_statement::do_execute_base_query(cql3::query_processor&, std::vector<cql3::statements::select_statement::primary_key>&&, service::query_state&, const cql3::query_options&, gc_clock::time_point, seastar::lw_shared_ptr<const service::pager::paging_state>) const::_ZNK4cql310statements30indexed_table_select_statement21do_execute_base_queryERNS_15query_processorEOSt6vectorINS0_16select_statement11primary_keyESaIS6_EERN7service11query_stateERKNS_13query_optionsENSt6chrono10time_pointI8gc_clockNSG_8durationIlSt5ratioILl1ELl1EEEEEEN7seastar13lw_shared_ptrIKNSA_5pager12paging_stateEEE.Frame*)::<lambda(auto:351&)> >; Reducer = query::result_merger]’
bad.cc:311181:114:   required from here
bad.cc:311194:9: internal compiler error: Segmentation fault
311194 |         }), std::move(oneshot_merger));
       |         ^
0xd5cbaf crash_signal
    ../../gcc/gcc/toplev.cc:314
0x68cb32 build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int)
    ../../gcc/gcc/cp/call.cc:11072
0x6caecc maybe_promote_temps
    ../../gcc/gcc/cp/coroutines.cc:3146
0x6caecc await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3757
0xfd93c3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11327
0x6ca691 await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3428
0xfd93c3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11327
0xfd9574 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11558
0x6ca691 await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3428
0xfd93c3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11327
0x6cac26 await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3417
0xfd93c3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11327
0x6ca691 await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3428
0xfd93c3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11327
0x6cac26 await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3417
0xfd93c3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11327
0x6ca691 await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3428
0xfd93c3 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11327
0xfd9574 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
    ../../gcc/gcc/tree.cc:11558
0x6ca691 await_statement_walker
    ../../gcc/gcc/cp/coroutines.cc:3428
Please submit a full bug report, with preprocessed source (by using -freport-bug).
avikivity commented 1 year ago

Sure, please copy me so I can help if needed and see the fix land. avi \@ scylladb.com.

marxin commented 1 year ago

Sure, will CC you!

marxin commented 1 year ago

Btw. can you build the source file with GCC 12? If so, please attach somewhere the pre-processed source file created with gcc12.

avikivity commented 1 year ago

gcc 12 has problems (recently fixed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98056), which is why I'm trying 13. I'll try 12 anyway to confirm.

avikivity commented 1 year ago

No, it failed on that bug. And in the same place, so I think the fix was incomplete.

marxin commented 1 year ago

gcc 12 has problems (recently fixed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98056), which is why I'm trying 13. I'll try 12 anyway to confirm.

Oh, looking into the bug! Yes, I also think the fix is incomplete. I'm reducing that right now with --clang-delta-std=c++98..

avikivity commented 1 year ago

Watching cvise reduce stuff is my favorite pastime!

marxin commented 1 year ago

Watching cvise reduce stuff is my favorite pastime!

Yeah, same for me! Let's see where can we go, the source file is pretty huge and the reduction is progressing slowly...

marxin commented 1 year ago

Now, I've switched to just released LLVM 16 and the reduction works with -std=c++17 (now a newer C++ standard version crashes in libclang-cpp.so.16). Anyway, the reduction should be faster now.

marxin commented 1 year ago

And I'm done and reported that as: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109227. Hopefully, it's still a valid code snippet, can you please check it? I'm not so much familiar with coroutines.

marxin commented 1 year ago

There's not much I can do with a crashing/stuck libLLVM, thus I'm closing it.