Issue 56670
Summary clang-format 14.0.0 crashes with AlignArrayOfStructures: Left
Labels new issue
Assignees
Reporter kivadiu
    The following C++ code produces a crash of clang-format when `AlignArrayOfStructures` is set to `Left`:
[minimal-example.tar.gz](https://github.com/llvm/llvm-project/files/9167087/minimal-example.tar.gz)

```
class Foo;  // remove this line and it works
// remove this line and it works

struct array {
  double m_values[2];
};

struct Bar {
  Bar(array) {}
};

void f(array, const Bar &) {}

int main(int argc, char **argv) {
  f(array{1., 2.}, Bar{{0, 0}});
  return 0;
}
```

```
$ clang-format --version
clang-format version 14.0.0 (Fedora 14.0.0-1.fc36)
```

```
clang-format --style=file -i x.cpp
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 --style=file -i x.cpp
 #0 0x00007f1e66c883f5 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM-14.so+0xc883f5)
 #1 0x00007f1e66c8867b (/lib64/libLLVM-14.so+0xc8867b)
 #2 0x00007f1e66c85cd4 llvm::sys::RunSignalHandlers() (/lib64/libLLVM-14.so+0xc85cd4)
 #3 0x00007f1e66c88cbd (/lib64/libLLVM-14.so+0xc88cbd)
 #4 0x00007f1e6583ea70 __restore_rt (/lib64/libc.so.6+0x3ea70)
 #5 0x00007f1e6f18d3d9 clang::format::WhitespaceManager::alignArrayInitializersLeftJustified(clang::format::WhitespaceManager::CellDescriptions&&) (/lib64/libclang-cpp.so.14+0x298d3d9)
 #6 0x00007f1e6f18e495 clang::format::WhitespaceManager::alignArrayInitializers(unsigned int, unsigned int) (/lib64/libclang-cpp.so.14+0x298e495)
 #7 0x00007f1e6f18e584 clang::format::WhitespaceManager::alignArrayInitializers() (/lib64/libclang-cpp.so.14+0x298e584)
 #8 0x00007f1e6f1922ec clang::format::WhitespaceManager::generateReplacements() (/lib64/libclang-cpp.so.14+0x29922ec)
 #9 0x00007f1e6f125b30 (/lib64/libclang-cpp.so.14+0x2925b30)
#10 0x00007f1e6f1592eb clang::format::TokenAnalyzer::process() (/lib64/libclang-cpp.so.14+0x29592eb)
#11 0x00007f1e6f1251f8 (/lib64/libclang-cpp.so.14+0x29251f8)
#12 0x00007f1e6f12525b (/lib64/libclang-cpp.so.14+0x292525b)
#13 0x00007f1e6f131933 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*) (/lib64/libclang-cpp.so.14+0x2931933)
#14 0x00007f1e6f13288c clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/lib64/libclang-cpp.so.14+0x293288c)
#15 0x000055b7430d5669 (/usr/bin/clang-format+0x11669)
#16 0x000055b7430cde00 (/usr/bin/clang-format+0x9e00)
#17 0x00007f1e65829550 __libc_start_call_main (/lib64/libc.so.6+0x29550)
#18 0x00007f1e65829609 __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x29609)
#19 0x000055b7430ce245 (/usr/bin/clang-format+0xa245)
./run_test : ligne 3 : 63459 Erreur de segmentation  (core dumped)clang-format --style=file -i x.cpp
```

Interestingly, if you remove one of the first 2 lines (useless), there is no crash.

Thanks
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to