<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102311>102311</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang++ C++ optimization crashes ClickHouse on PowerPC64le platform
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
HarryLeeIBM
</td>
</tr>
</table>
<pre>
I used Ubuntu clang version 16.0.6 to build ClickHouse(v24.7.x) using cross-compiling for PowerPC64le platform and found ClickHouse crashes. When I build ClickHouse with -O0 option it doesn't crash, so it could be a wrong optimization issue.
To reproduce the issue, use the following steps:
1. git clone ClickHouse and install necessary tools (see details: https://github.com/ClickHouse/ClickHouse/blob/master/docs/en/development/build.md).
2. Use the following commands to do cross-compiling under ClickHouse folder:
```
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_OPTIM=ON -DGLIBC_COMPATIBILITY=OFF -DENABLE_RDKAFKA=ON -DBUILD_SHARED_LIBS=OFF -DITK_DYNAMIC_LOADING=OFF -DENABLE_AMQPCPP=OFF -DENABLE_AVRO=ON -DENABLE_CAPNP=OFF -DENABLE_CASSANDRA=OFF -DENABLE_H3=OFF -DENABLE_HDFS=OFF -DENABLE_MSGPACK=OFF -DENABLE_MYSQL=OFF -DENABLE_NLP=OFF -DENABLE_ODBC=OFF -DENABLE_ORC=OFF -DENABLE_PARQUET=OFF -DENABLE_ROCKSDB=OFF -DENABLE_SQLITE=OFF -DENABLE_SHELL_COMMANDS=0 -DENABLE_PLAY=0 -DADD_GDB_INDEX_FOR_GOLD=1 -DCLICKHOUSE_OFFICIAL_BUILD=1 -DCMAKE_TOOLCHAIN_FILE=cmake/linux/toolchain-ppc64le.cmake ..
```
3. Copy clickhouse executable under build/progams to a power pc 64le machine.
4. Run "clickhouse server" to start the ClickHouse server
5. use another terminal to run "clickhouse client" to run ClickHouse client. Under the prompt, run SQL:
`select if(in(dummy, tuple(0, 1)), 'ok', 'ok') from remote('localhost', system.one) settings legacy_column_name_of_tuple_literal=1, prefer_localhost_replica=0;`
Then you will notice the server crashes and core dump is created. By analyzing the core dump, the stack trace is as following:
```
Program terminated with signal SIGSEGV, Segmentation fault.
#0 std::__1::construct_at[abi:v15000]<DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node**>(DB::ExecutingGraph::Node**, DB::ExecutingGraph::Node*&&) (__location=0x7f43d378418304bc, __args=<optimized out>)
at ./contrib/llvm-project/libcxx/include/__memory/construct_at.h:35
warning: 35 ./contrib/llvm-project/libcxx/include/__memory/construct_at.h: No such file or directory
[Current thread is 1 (Thread 0x75a79cf69110 (LWP 262772))]
(gdb) bt
#0 std::__1::construct_at[abi:v15000]<DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node**>(DB::ExecutingGraph::Node**, DB::ExecutingGraph::Node*&&) (__location=0x7f43d378418304bc, __args=<optimized out>)
at ./contrib/llvm-project/libcxx/include/__memory/construct_at.h:35
#1 std::__1::allocator_traits<AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*> >::construct[abi:v15000]<DB::ExecutingGraph::Node*, DB::ExecutingGraph::Node*, void, void>(AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*>&, DB::ExecutingGraph::Node**, DB::ExecutingGraph::Node*&&) (__p=0x7f43d378418304bc,
__args=<optimized out>)
at ./contrib/llvm-project/libcxx/include/__memory/allocator_traits.h:298
#2 std::__1::deque<DB::ExecutingGraph::Node*, AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*> >::push_back (this=0x75a79cf67ee0, __v=<optimized out>)
at ./contrib/llvm-project/libcxx/include/deque:1967
#3 std::__1::queue<DB::ExecutingGraph::Node*, std::__1::deque<DB::ExecutingGraph::Node*, AllocatorWithMemoryTracking<DB::ExecutingGraph::Node*> > >::push[abi:v15000](DB::ExecutingGraph::Node*&&) (this=0x75a79cf67ee0, __v=<optimized out>)
at ./contrib/llvm-project/libcxx/include/queue:365
#4 DB::ExecutingGraph::updateNode (this=0x75a795831900, pid=0, queue=...,
async_queue=...)
at ./ppc18-rel/./src/Processors/Executors/ExecutingGraph.cpp:344
#5 0x0000000022a67c74 in DB::PipelineExecutor::executeStepImpl (
this=0x75a7958b2a18, thread_num=<optimized out>, yield_flag=0x0)
at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:291
--Type <RET> for more, q to quit, c to continue without paging--c
#6 0x0000000022a6728c in DB::PipelineExecutor::executeSingleThread (
this=0x75a7958b2a18, thread_num=0)
at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:238
#7 DB::PipelineExecutor::executeImpl (this=0x75a7958b2a18,
num_threads=<optimized out>, concurrency_control=<optimized out>)
at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:410
#8 0x0000000022a66f74 in DB::PipelineExecutor::execute (this=0x75a7958b2a18,
num_threads=1, concurrency_control=<optimized out>)
at ./ppc18-rel/./src/Processors/Executors/PipelineExecutor.cpp:110
#9 0x0000000022a77a64 in DB::threadFunction (data=..., thread_group=...,
num_threads=1,
concurrency_control=<error reading variable: Unable to access DWARF register number 73>)
at ./ppc18-rel/./src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:83
#10 DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0::operator()() const (this=<optimized out>)
at ./ppc18-rel/./src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:109
#11 std::__1::__invoke[abi:v15000]<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&) (__f=...)
at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:394
#12 _ZNSt3__118__apply_tuple_implB6v15000IRZN2DB28PullingAsyncPipelineExecutor4pullERNS1_5ChunkEmE3$_0RNS_5tupleIJEEETpTnmJEEEDcOT_OT0_NS_15__tuple_indicesIJXspT1_EEEE (__f=..., __t=...) at ./contrib/llvm-project/libcxx/include/tuple:1789
#13 std::__1::apply[abi:v15000]<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&) (__f=..., __t=...)
at ./contrib/llvm-project/libcxx/include/tuple:1798
#14 ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}::operator()() (this=<optimized out>) at ./src/Common/ThreadPool.h:251
#15 std::__1::__invoke[abi:v15000]<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&) (__f=...)
at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:394
#16 std::__1::__invoke_void_return_wrapper<void, true>::__call<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}&>(ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}&) (__args=...)
at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:479
#17 std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}, void ()>::operator()[abi:v15000]() (
this=<optimized out>)
at ./contrib/llvm-project/libcxx/include/__functional/function.h:235
#18 std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::{lambda()#1}, void ()> >(std::__1::__function::__policy_storage const*) (
__buf=<optimized out>)
at ./contrib/llvm-project/libcxx/include/__functional/function.h:716
#19 0x000000001ad690cc in std::__1::__function::__policy_func<void ()>::operator()[abi:v15000]() const (this=0x75a79cf68570)
at ./contrib/llvm-project/libcxx/include/__functional/function.h:848
#20 std::__1::function<void()>::operator() (this=0x75a79cf68570)
at ./contrib/llvm-project/libcxx/include/__functional/function.h:1187
#21 ThreadPoolImpl<std::__1::thread>::worker (this=0x75a97c042e40,
thread_it=...) at ./ppc18-rel/./src/Common/ThreadPool.cpp:462
#22 0x000000001ad6e274 in ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}::operator()() const (this=0x75a7ab9f27c8)
at ./ppc18-rel/./src/Common/ThreadPool.cpp:219
#23 std::__1::__invoke[abi:v15000]<ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}>(ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}&&) (__f=...)
at ./contrib/llvm-project/libcxx/include/__functional/invoke.h:394
#24 _ZNSt3__116__thread_executeB6v15000INS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZN14ThreadPoolImplINS_6threadEE12scheduleImplIvEET_NS_8functionIFvvEEE8PriorityNS_8optionalImEEbEUlvE0_JETpTnmJEEEvRNS_5tupleIJSA_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE (__t=...)
at ./contrib/llvm-project/libcxx/include/thread:284
#25 std::__1::__thread_proxy[abi:v15000]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, Priority, std::__1::optional<unsigned long>, bool)::{lambda()#2}> >(void*) (
__vp=0x75a7ab9f27c0) at ./contrib/llvm-project/libcxx/include/thread:295
#26 0x000075a97cdf8838 in start_thread ()
from /lib/powerpc64le-linux-gnu/libpthread.so.0
#27 0x000075a97ccfba44 in clone () from /lib/powerpc64le-linux-gnu/libc.so.6
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW11zm7rW_jXkRhMPCNvgi1xgwCm7juMdu6en-0YjhGzzRiAqhBOfX_-OEMTEdrKdNm3P2dNMxjZCX-tZj9ZaWgJcluk6p_TKGIyNQXCBK7nh4uoDFmI3pTQa31zEPNldRaAqaQI-xVUuK0AYztdgS0WZ8hxYw57ZGwLJQVylLAE-S8n9B16V1IDuFvZ7Tu_RgCNQlWm-BkTwsrwkPCtSpq5XXIA5f6Bi7g_7jIKCYbniIgM4T8CKV3m3Q0AELje07IHPG5qD6GhE8JDKDbi8NQEvpJpcKkHCaZkb0JG6tQF9UHJ1g_CKJSCmAIMHwfN13SZL_4N1y7KsaM8wA8P09OeSA0ELwZOKUCA3VFdR_amRVcGKM8YflFilpEVp2E1LqwfWakDGc9qdrZIxzUuJGQM5JbQssdgByTkrgQHdklKQUIlTproCGyl1n3BiwMk6lZsq7hGeGXDSxfz5Rcx4bMBJhktJhQEnCSelASc0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