<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/98185>98185</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Error returned from Expected's "takeError" must be handled, otherwise it will cause core dump for debug build
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nickhuang99
</td>
</tr>
</table>
<pre>
The following snippet appearing in a couple of tools code (_clang/tools/clang-check/ClangCheck.cpp_, _clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp_) will cause core dump if **building debug** type because **Error** returned from **takeError** must be handled. i.e.
`toString(ExpectedParser.takeError());` can handleAllError.
`if (!ExpectedParser) {`
`llvm::errs() << ExpectedParser.takeError();`
`return 1;`
` }`
Please note: this issue won't happen for release build because **LLVM_ENABLE_ABI_BREAKING_CHECKS** macro is only enabled when debug build.
` Error takeError() {`
`#if LLVM_ENABLE_ABI_BREAKING_CHECKS`
`Unchecked = false;`
`#endif`
The following is core dump for invalid command line param.
$ ./clang-check --wat
clang-check: Unknown command line argument '--wat'. Try: './clang-check --help'
clang-check: Did you mean '-h'?
clang-check: Not enough positional command line arguments specified!
Must specify at least 1 positional argument: See: ./clang-check --help
Program aborted due to an unhandled Error:
clang-check: Unknown command line argument '--wat'. Try: './clang-check --help'
clang-check: Did you mean '-h'?
clang-check: Not enough positional command line arguments specified!
Must specify at least 1 positional argument: See: ./clang-check --help
#0 0x00007ca08fce17a2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/nick/workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
#1 0x00007ca08fce1bc3 PrintStackTraceSignalHandler(void*) /home/nick/workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
#2 0x00007ca08fcdf013 llvm::sys::RunSignalHandlers() /home/nick/workspace/llvm-project/llvm/lib/Support/Signals.cpp:105:20
#3 0x00007ca08fce103a SignalHandler(int) /home/nick/workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#4 0x00007ca08a642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007ca08a6969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0x00007ca08a6969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#7 0x00007ca08a6969fc pthread_kill ./nptl/pthread_kill.c:89:10
#8 0x00007ca08a642476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#9 0x00007ca08a6287f3 abort ./stdlib/abort.c:81:7
#10 0x00007ca08fba0661 /home/nick/workspace/llvm-project/llvm/lib/Support/Error.cpp:136:8
#11 0x00005d0e0bd5abc8 llvm::Error::assertIsChecked() /home/nick/workspace/llvm-project/llvm/include/llvm/Support/Error.h:274:3
#12 0x00005d0e0bd5ab3e llvm::Error::~Error() /home/nick/workspace/llvm-project/llvm/include/llvm/Support/Error.h:235:18
#13 0x00005d0e0bd56cf7 main /home/nick/workspace/llvm-project/clang/tools/clang-check/ClangCheck.cpp:208:12
#14 0x00007ca08a629d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#15 0x00007ca08a629e40 call_init ./csu/../csu/libc-start.c:128:20
#16 0x00007ca08a629e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#17 0x00005d0e0bd564e5 _start (./clang-check+0x124e5)
Aborted (core dumped)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV0uP4zYS_jX0pdCCRNl6HHxwP5wEmRkM0jN7NWiqZHGbJgWSGrsv-9sXJN1tSeMkm-zObYGGW3zUx6-eZDFrxUEhrsnqnqweF2xwnTZrJfhLNzB1qOvFXjeva5I-knTzpUNotZT6JNQBrBJ9jw5Y3yMzfkYoYMD10EsE3YLTWlrgukEgtNpxydSB0G2YJnQbxne8Q_5C6PbBjx78IOF9vyP0AX5HAs-uwfbuyPpehOUg-nR2j9h-ZP1PqC4INZyElMDZ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