mygitljf wrote:

When I carefully examined,I found another crash that is not covered by the 
current `parseConditional` guard. In particular, this one has balanced braces 
but still aborts on an assertions .

command:
```bash
(base) lianjf@ubuntu:~/llvmPR$ printf '%s' '{ operator } a' > /tmp/t.cpp
(base) lianjf@ubuntu:~/llvmPR$ 
CF=/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format
(base) lianjf@ubuntu:~/llvmPR$ $CF --style=LLVM /tmp/t.cpp
```
assertion:
```bash
clang-format: 
/home/lianjf/llvmPR/llvm-src-199075/clang/lib/Format/TokenAnnotator.cpp:1217: 
bool clang::format::{anonymous}::AnnotatingParser::parseBrace(): Assertion 
`!Scopes.empty()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.      Program arguments: 
/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format --style=LLVM /tmp/t.cpp
 #0 0x0000557453ad0c12 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0xa9c12)
 #1 0x0000557453acd71c llvm::sys::RunSignalHandlers() 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0xa671c)
 #2 0x0000557453acd87c SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f4fb590b520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f4fb595f9fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f4fb595f9fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f4fb595f9fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f4fb590b476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f4fb58f17f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f4fb58f171b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f4fb5902e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000557453b7180a clang::format::(anonymous 
namespace)::AnnotatingParser::parseBrace() TokenAnnotator.cpp:0:0
#12 0x0000557453b73688 clang::format::(anonymous 
namespace)::AnnotatingParser::parseLine() TokenAnnotator.cpp:0:0
#13 0x0000557453b743d5 
clang::format::TokenAnnotator::annotate(clang::format::AnnotatedLine&) 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0x14d3d5)
#14 0x0000557453b578de clang::format::TokenAnalyzer::process(bool) 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0x1308de)
#15 0x0000557453b23feb 
clang::format::internal::reformat(clang::format::FormatStyle const&, 
llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned 
int, unsigned int, llvm::StringRef, 
clang::format::FormattingAttemptStatus*)::'lambda6'(clang::format::Environment 
const&)::operator()(clang::format::Environment const&) const (.isra.0) 
Format.cpp:0:0
#16 0x0000557453b241c4 
std::_Function_handler<std::pair<clang::tooling::Replacements, unsigned int> 
(clang::format::Environment const&), 
clang::format::internal::reformat(clang::format::FormatStyle const&, 
llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned 
int, unsigned int, llvm::StringRef, 
clang::format::FormattingAttemptStatus*)::'lambda6'(clang::format::Environment 
const&)>::_M_invoke(std::_Any_data const&, clang::format::Environment const&) 
Format.cpp:0:0
#17 0x0000557453b200d4 
clang::format::internal::reformat(clang::format::FormatStyle const&, 
llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned 
int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus*) 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0xf90d4)
#18 0x0000557453b21f6c clang::format::reformat(clang::format::FormatStyle 
const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, 
llvm::StringRef, clang::format::FormattingAttemptStatus*) 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0xfaf6c)
#19 0x0000557453a62c77 clang::format::format(llvm::StringRef, bool) 
ClangFormat.cpp:0:0
#20 0x0000557453a47cd0 main 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0x20cd0)
#21 0x00007f4fb58f2d90 __libc_start_call_main 
./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#22 0x00007f4fb58f2e40 call_init ./csu/../csu/libc-start.c:128:20
#23 0x00007f4fb58f2e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#24 0x0000557453a5a935 _start 
(/home/lianjf/llvmPR/llvm-build-199075/bin/clang-format+0x33935)
Aborted (core dumped)
```

Two related malformed inputs hit the same assertion: `{ operator } a }` ,  `{ 
operator } a } b`

I will then submit a commit to fix this issue.

https://github.com/llvm/llvm-project/pull/199098
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to