Issue 98185
Summary Error returned from Expected's "takeError" must be handled, otherwise it will cause core dump for debug build
Labels new issue
Assignees
Reporter nickhuang99
    
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)


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to