<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102192>102192</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] RISCV TableGen segfaults and has UBSan failures on PPC64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
awilfox
</td>
</tr>
</table>
<pre>
While building Clang 18.1.8 on a Power9 64-bit PowerPC (big endian) system:
```
[ 23%] Building riscv_sifive_vector_builtins.inc...
#0 0x0000000122b0c3e0 SignalHandler(int) Signals.cpp.o:0:0
#1 0x00003fff9ab92444 (+0x444)
#2 0x0000000122aa658c clang::RISCV::RVVIntrinsic::RVVIntrinsic(llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::StringRef, bool, bool, bool, clang::RISCV::PolicyScheme, bool, bool, llvm::StringRef, std::vector<clang::RISCV::RVVType*, std::allocator<clang::RISCV::RVVType*>> const&, std::vector<long, std::allocator<long>> const&, std::vector<llvm::StringRef, std::allocator<llvm::StringRef>> const&, unsigned int, clang::RISCV::Policy, bool) /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/lib/Support/RISCVVIntrinsicUtils.cpp:1004:14
#3 0x0000000122a93f18 std::__detail::_MakeUniq<clang::RISCV::RVVIntrinsic>::__single_object std::make_unique<clang::RISCV::RVVIntrinsic, llvm::StringRef&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, llvm::StringRef&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, llvm::StringRef&, bool, bool, bool&, clang::RISCV::PolicyScheme&, bool&, bool&, llvm::StringRef&, std::vector<clang::RISCV::RVVType*, std::allocator<clang::RISCV::RVVType*>>&, std::vector<long, std::allocator<long>>&, std::vector<llvm::StringRef, std::allocator<llvm::StringRef>>&, unsigned int&, clang::RISCV::Policy&, bool&>(llvm::StringRef&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, llvm::StringRef&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, llvm::StringRef&, bool&&, bool&&, bool&, clang::RISCV::PolicyScheme&, bool&, bool&, llvm::StringRef&, std::vector<clang::RISCV::RVVType*, std::allocator<clang::RISCV::RVVType*>>&, std::vector<long, std::allocator<long>>&, std::vector<llvm::StringRef, std::allocator<llvm::StringRef>>&, unsigned int&, clang::RISCV::Policy&, bool&) /usr/include/c++/13.3.0/bits/unique_ptr.h:1070:30
#4 0x0000000122a93f18 (anonymous namespace)::RVVEmitter::createRVVIntrinsics(std::vector<std::unique_ptr<clang::RISCV::RVVIntrinsic, std::default_delete<clang::RISCV::RVVIntrinsic>>, std::allocator<std::unique_ptr<clang::RISCV::RVVIntrinsic, std::default_delete<clang::RISCV::RVVIntrinsic>>>>&, std::vector<(anonymous namespace)::SemaRecord, std::allocator<(anonymous namespace)::SemaRecord>>*) (.constprop.0) /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/RISCVVEmitter.cpp:592:57
#5 0x0000000122a944c0 createBuiltins /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/RISCVVEmitter.cpp:425:9
#6 0x0000000122a944c0 clang::EmitRVVBuiltins(llvm::RecordKeeper&, llvm::raw_ostream&) /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/RISCVVEmitter.cpp:774:37
#7 0x0000000122aa1c5c (anonymous namespace)::ClangTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/TableGen.cpp:552:20
#8 0x0000000122aa0fac bool std::__invoke_impl<bool, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&>(std::__invoke_other, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&) /usr/include/c++/13.3.0/bits/invoke.h:61:36
#9 0x0000000122aa0fac std::enable_if<is_invocable_r_v<bool, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&>, bool>::type std::__invoke_r<bool, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&>(bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&) /usr/include/c++/13.3.0/bits/invoke.h:114:35
#10 0x0000000122aa0fac std::_Function_handler<bool (llvm::raw_ostream&, llvm::RecordKeeper&), bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)>::_M_invoke(std::_Any_data const&, llvm::raw_ostream&, llvm::RecordKeeper&) /usr/include/c++/13.3.0/bits/std_function.h:290:30
#11 0x0000000122b1f5f4 llvm::TableGenMain(char const*, std::function<bool (llvm::raw_ostream&, llvm::RecordKeeper&)>) (../../../bin/clang-tblgen+0x11f5f4)
#12 0x0000000122a20018 main /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/TableGen.cpp:597:22
#13 0x00003fff9aac8038 libc_start_main_stage2 /usr/src/packages/system/musl/src/musl-1.2.3/src/env/__libc_start_main.c:95:2
#14 0x00003fff9aac80b4 __libc_start_main /usr/src/packages/system/musl/src/musl-1.2.3/src/env/__libc_start_main.c:86:9
#15 0x0000000122a23d98 _start_c /usr/src/packages/system/musl/src/musl-1.2.3/crt/crt1.c:18:2
#16 0x0000000122a23d40 _start (../../../bin/clang-tblgen+0x23d40)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: ../../../bin/clang-tblgen -gen-riscv-sifive-vector-builtins -I /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/include/clang/Basic -I/home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/include -I/home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/build/include -I/usr/lib/llvm18/include /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/include/clang/Basic/riscv_sifive_vector.td --write-if-changed -o /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/build/include/clang/Basic/riscv_sifive_vector_builtins.inc
make[2]: *** [include/clang/Basic/CMakeFiles/ClangRISCVSiFiveVectorBuiltins.dir/build.make:154: include/clang/Basic/riscv_sifive_vector_builtins.inc] Segmentation fault
```
Building clang-tblgen with `-fsanitize=undefined` and using `UBSAN_OPTIONS=print_stacktrace=1` yielded a lot of output that does not fit in a GitHub issue, but is uploaded at [clang-tblgen-ubsan-output-gwyn-202408061309.txt](https://github.com/user-attachments/files/16514270/clang-tblgen-ubsan-output-gwyn-202408061309.txt). The summary output was:
```
/home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/RISCVVEmitter.cpp:465:44: runtime error: member call on null pointer of type 'struct unique_ptr'
/usr/include/c++/13.3.0/bits/unique_ptr.h:470:27: runtime error: member access within null pointer of type 'const struct unique_ptr'
/usr/include/c++/13.3.0/bits/unique_ptr.h:470:27: runtime error: member call on null pointer of type 'const struct __uniq_ptr_impl'
/usr/include/c++/13.3.0/bits/unique_ptr.h:470:27: runtime error: member access within null pointer of type 'const struct unique_ptr'
/usr/include/c++/13.3.0/bits/unique_ptr.h:199:63: runtime error: member access within null pointer of type 'const struct __uniq_ptr_impl'
/usr/include/c++/13.3.0/bits/unique_ptr.h:199:63: runtime error: reference binding to null pointer of type 'const struct tuple'
/usr/include/c++/13.3.0/bits/unique_ptr.h:199:63: runtime error: member access within null pointer of type 'const struct __uniq_ptr_impl'
/usr/include/c++/13.3.0/tuple:1810:36: runtime error: member access within null pointer of type 'const struct tuple'
/usr/include/c++/13.3.0/tuple:1810:36: runtime error: member access within null pointer of type 'const struct tuple'
/usr/include/c++/13.3.0/tuple:272:71: runtime error: member access within null pointer of type 'const struct _Tuple_impl'
/usr/include/c++/13.3.0/tuple:272:71: runtime error: member access within null pointer of type 'const struct _Tuple_impl'
/usr/include/c++/13.3.0/tuple:237:60: runtime error: member access within null pointer of type 'const struct _Head_base'
/usr/include/c++/13.3.0/tuple:237:60: runtime error: member access within null pointer of type 'const struct _Head_base'
/usr/include/c++/13.3.0/tuple:1810:40: runtime error: reference binding to null pointer of type 'struct RVVIntrinsic *'
/usr/include/c++/13.3.0/bits/unique_ptr.h:199:67: runtime error: load of null pointer of type 'struct RVVIntrinsic *'
```
before giving another stack trace:
```
#0 0x00000001333981e0 SignalHandler(int) Signals.cpp.o:0:0
#1 0x00003fff9bae2444 (+0x444)
#2 0x00000001332c8004 std::unique_ptr<clang::RISCV::RVVIntrinsic, std::default_delete<clang::RISCV::RVVIntrinsic>>::get() const /usr/include/c++/13.3.0/bits/unique_ptr.h:470:27
#3 0x00000001332c8004 createCodeGen /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/RISCVVEmitter.cpp:465:44
#4 0x00000001332c8004 clang::EmitRVVBuiltinCG(llvm::RecordKeeper&, llvm::raw_ostream&) /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/RISCVVEmitter.cpp:778:36
#5 0x00000001333125c0 (anonymous namespace)::ClangTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/TableGen.cpp:555:21
#6 0x000000013330dad8 bool std::__invoke_impl<bool, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&>(std::__invoke_other, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&) /usr/include/c++/13.3.0/bits/invoke.h:61:36
#7 0x000000013330dad8 std::enable_if<is_invocable_r_v<bool, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&>, bool>::type std::__invoke_r<bool, bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&>(bool (*&)(llvm::raw_ostream&, llvm::RecordKeeper&), llvm::raw_ostream&, llvm::RecordKeeper&) /usr/include/c++/13.3.0/bits/invoke.h:114:35
#8 0x000000013330dad8 std::_Function_handler<bool (llvm::raw_ostream&, llvm::RecordKeeper&), bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)>::_M_invoke(std::_Any_data const&, llvm::raw_ostream&, llvm::RecordKeeper&) /usr/include/c++/13.3.0/bits/std_function.h:290:30
#9 0x00000001333ab3f4 llvm::TableGenMain(char const*, std::function<bool (llvm::raw_ostream&, llvm::RecordKeeper&)>) (../../../bin/clang-tblgen+0x71b3f4)
#10 0x0000000132fd85a8 main /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/utils/TableGen/TableGen.cpp:597:22
#11 0x00003fff9ba21038 libc_start_main_stage2 /usr/src/packages/system/musl/src/musl-1.2.3/src/env/__libc_start_main.c:95:2
#12 0x00003fff9ba210b4 __libc_start_main /usr/src/packages/system/musl/src/musl-1.2.3/src/env/__libc_start_main.c:86:9
#13 0x0000000132fdc1f8 _start_c /usr/src/packages/system/musl/src/musl-1.2.3/crt/crt1.c:18:2
#14 0x0000000132fdc1a0 _start (../../../bin/clang-tblgen+0x34c1a0)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: ../../../bin/clang-tblgen -gen-riscv-sifive-vector-builtin-codegen -I /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/include/clang/Basic -I/home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/include -I/home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/build/include -I/usr/lib/llvm18/include /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/include/clang/Basic/riscv_sifive_vector.td --write-if-changed -o /home/awilcox/Code/awilfox/rust-next/user/clang/src/llvm-project-18.1.8.src/clang/build/include/clang/Basic/riscv_sifive_vector_builtin_cg.inc
make[2]: *** [include/clang/Basic/CMakeFiles/ClangRISCVSiFiveVectorBuiltinCG.dir/build.make:154: include/clang/Basic/riscv_sifive_vector_builtin_cg.inc] Segmentation fault (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW11zmzwW_jXKjQYGJMBwkQvbidvObt83U7fZS0YIgbUB4VcS-dhfvyOBvx3HbdLEbdNJHSOQ9JwPnXOkhxCleCkYOwfhCIQXZ6TVs0aekzteFc39WdbkD-f_mfGKwazlVc5FCccVESX0Y9d3Y9gISOBVc8dkAqPAybjurq7GEKA44yVkIudEAJRA9aA0qwEeAu8CeIvPyOt_ustwBBEGKAThBRwtppRc0dtU8YLfsvSWUd3I1ODRXCiXC-q6btcdAoQ96N173T8focyjmHlwyktBqo9E5BWTAMVcaAOpa1Yunc_dBuChZ_8vh_L7oXBRFAnJEhQEgZELoJF3HwQBQMnqYbQxLyFRGFNIjbKMyHj45dN0fN1_vb7-JLTkQnG6pwXFVXVbdzemprH8wgqAxvBnNmdNU-37vV-Cq6bi9GFKZ6xm-3o9MonSedfaGRHg8aMK-vowZwANN3qRqmooObIjvgT4EtJGKA1QtH_2qhHlozPYm0eN8oSwG4PueXZ3jlbYZZlD66eHjbBSewIBmswaY5GJWcG0uQdoMm7yRUNhG2SrtCPYvQZo0iqzHCbd-GiiJAVoYjA6c9n8l1HtdAvd7e4snqt4BtBk2s7njTTDWFArD_6mebeoAB76nheYX8FqpeDNlZLgwo9X2krTnGnCq_7qM7l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