Issue 184040
Summary [clang-format] LLVM ERROR: out of memory when formatting ext/nlohmann/json.hpp (clang-format-20)
Labels clang-format
Assignees
Reporter rebroad
    ### Description
`clang-format-20` aborts with `LLVM ERROR: out of memory` on a large header (`ext/nlohmann/json.hpp`) when run with a valid `.clang-format` file and `--assume-filename`.

This appears to be an internal formatter memory blow-up, not a normal timeout.

### Reproduction
Command:

```bash
clang-format-20 \
 -style=file:/tmp/tmp.4AqlzSjBws \
  -assume-filename=ext/nlohmann/json.hpp \
  /tmp/tmp.zKNPxUzeKY/src
```

(Equivalent repro is formatting `nlohmann/json.hpp` with a C++ style file.)

### Expected behavior
`clang-format` should either:
- format successfully, or
- fail gracefully with a normal error code/message (without aborting).

### Actual behavior
Process aborts with:

- `LLVM ERROR: out of memory`
- exit code `134` (SIGABRT)

Crash backtrace:

```text
LLVM ERROR: out of memory
Allocation failed
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/
Stack dump:
0.	Program arguments: clang-format-20 -style=file:/tmp/tmp.4AqlzSjBws -assume-filename=ext/nlohmann/json.hpp /tmp/tmp.zKNPxUzeKY/src
 #0 0x000078a66be2bc7f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM.so.20.1+0x102bc7f)
 #1 0x000078a66be29989 llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM.so.20.1+0x1029989)
 #2 0x000078a66be2c390 (/lib/x86_64-linux-gnu/libLLVM.so.20.1+0x102c390)
 #3 0x000078a66a645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x000078a66a69eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x000078a66a69eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x000078a66a69eb2c pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x000078a66a64527e raise ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x000078a66a6288ff abort ./stdlib/abort.c:81:7
 #9 0x000078a66bd7e6cd llvm::report_bad_alloc_error(char const*, bool) (/lib/x86_64-linux-gnu/libLLVM.so.20.1+0xf7e6cd)
#10 0x000078a66bdbae03 llvm::SmallVectorBase<unsigned int>::mallocForGrow(void*, unsigned long, unsigned long, unsigned long&) (/lib/x86_64-linux-gnu/libLLVM.so.20.1+0xfbae03)
#11 0x000078a676ab7f0d llvm::SmallVectorTemplateBase<clang::format::UnwrappedLine, false>::grow(unsigned long) (/usr/lib/llvm-20/bin/../lib/libclang-cpp.so.20.1+0x32b7f0d)
#12 0x000078a676acbc0e (/usr/lib/llvm-20/bin/../lib/libclang-cpp.so.20.1+0x32cbc0e)
#13 0x000078a676ae6540 clang::format::UnwrappedLineParser::parse() (/usr/lib/llvm-20/bin/../lib/libclang-cpp.so.20.1+0x32e6540)
#14 0x000078a676acaf39 clang::format::TokenAnalyzer::process(bool) (/usr/lib/llvm-20/bin/../lib/libclang-cpp.so.20.1+0x32caf39)
#15 0x000078a676a92ad3 clang::format::guessLanguage(llvm::StringRef, llvm::StringRef) (/usr/lib/llvm-20/bin/../lib/libclang-cpp.so.20.1+0x3292ad3)
#16 0x000078a676a92e10 clang::format::getStyle(llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::vfs::FileSystem*, bool, void (*)(llvm::SMDiagnostic const&, void*)) (/usr/lib/llvm-20/bin/../lib/libclang-cpp.so.20.1+0x3292e10)
#17 0x00005c00d86a346d (/usr/lib/llvm-20/bin/clang-format+0xc46d)
#18 0x00005c00d86a1b0a (/usr/lib/llvm-20/bin/clang-format+0xab0a)
#19 0x000078a66a62a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#20 0x000078a66a62a28b call_init ./csu/../csu/libc-start.c:128:20
#21 0x000078a66a62a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#22 0x00005c00d869ee65 (/usr/lib/llvm-20/bin/clang-format+0x7e65)
Aborted (core dumped)
```

### Environment
- OS: Ubuntu 24.04 (x86_64)
- clang-format: `clang-format-20` (Ubuntu package, 20.1.2)
- Invocation context: batch script scanning many tracked C/C++ files; crash is reproducible on this specific file.

### Notes / Workaround
Current workaround is to skip this file (or apply size/memory/time guards), but this is not ideal for tooling reliability.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to