Issue |
130859
|
Summary |
clang-format (LLVM 19) SIGSEGV when formatting macro that generates function declaration
|
Labels |
clang-format
|
Assignees |
|
Reporter |
eliminmax
|
Defining the following macro then adding it to the `Macros` section of `.clang-format` causes both the Debian bookworm-updates build of `clang-format-19` and the `clang-format` from the Linux x64 tarball in the GitHub release for LLVM 19.1.7 to segfault.
```c
#define UNIT_TEST(foo) static void foo(void)
```
The most bare-bones files that reproduce it I've found is as follows:
**src.c**:
```c
#define UNIT_TEST(name) static void name(void)
UNIT_TEST(test_fn) {
}
```
**.clang-format**
```yaml
---
Macros:
- UNIT_TEST
```
`clang-format` (LLVM 19.1.7) output:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/eliminmax/Downloads/clang-format src.c
#0 0x000055a0c49bcc91 PrintStackTraceSignalHandler(void*) (.llvm.12627951935020062282) Signals.cpp:0:0
#1 0x000055a0c49bd856 SignalHandler(int) Signals.cpp:0:0
#2 0x00007fe05085b050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)
#3 0x000055a0c4a442f0 clang::format::TokenAnalyzer::process(bool) (/home/eliminmax/Downloads/clang-format+0x21f2f0)
#4 0x000055a0c4a10bc1 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*)::$_5>::_M_invoke(std::_Any_data const&, clang::format::Environment const&) Format.cpp:0:0
#5 0x000055a0c49f4b87 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/eliminmax/Downloads/clang-format+0x1cfb87)
#6 0x000055a0c49f5693 clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/home/eliminmax/Downloads/clang-format+0x1d0693)
#7 0x000055a0c4964be8 clang::format::format(llvm::StringRef, bool) ClangFormat.cpp:0:0
#8 0x000055a0c4961ac8 main (/home/eliminmax/Downloads/clang-format+0x13cac8)
#9 0x00007fe05084624a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#10 0x00007fe050846305 call_init ./csu/../csu/libc-start.c:128:20
#11 0x00007fe050846305 __libc_start_main ./csu/../csu/libc-start.c:347:5
#12 0x000055a0c4960905 _start (/home/eliminmax/Downloads/clang-format+0x13b905)
Segmentation fault
```
`clang-format-19` (Debian `clang-format-19` package):
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: clang-format-19 src.c
#0 0x00007f710deb72c6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xeb72c6)
#1 0x00007f710deb4f70 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xeb4f70)
#2 0x00007f710deb798b (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xeb798b)
#3 0x00007f710ce5b050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)
#4 0x00007f711809a6d2 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x349a6d2)
#5 0x00007f711809a266 clang::format::TokenAnalyzer::process(bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x349a266)
#6 0x00007f7118079515 (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x3479515)
#7 0x00007f7118061d65 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*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x3461d65)
#8 0x00007f7118062be1 clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x3462be1)
#9 0x0000561961931fb1 (/usr/lib/llvm-19/bin/clang-format+0xcfb1)
#10 0x000056196192f66b (/usr/lib/llvm-19/bin/clang-format+0xa66b)
#11 0x00007f710ce4624a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#12 0x00007f710ce46305 call_init ./csu/../csu/libc-start.c:128:20
#13 0x00007f710ce46305 __libc_start_main ./csu/../csu/libc-start.c:347:5
#14 0x000056196192c471 (/usr/lib/llvm-19/bin/clang-format+0x7471)
```
The binary from the latest release does not have this issue, but I could not find any issue reporting anything similar, and no commits since that come up when running `git log --since=2025-01-01 --grep='\[clang-format\]' main` mention anything related to memory, segmentation faults, use-after-free, out of bounds, or the like.
`clang-format` (LLVM 20.1.0) output:
```
#define UNIT_TEST(name) static void name(void)
UNIT_TEST(test_fn) {
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs