<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56670>56670</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-format 14.0.0 crashes with AlignArrayOfStructures: Left
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kivadiu
      </td>
    </tr>
</table>

<pre>
    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
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV21v4jgQ_jXwxSJKnBeSD3wAWu721NWt2mrvI3KSCfjqxMh2-rK__sYOLZgtu_S00h1C4JfJM89Mxp6ZUtYvs_stkEYKIZ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