<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68975>68975</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Segmentation fault during check modernize-loop-convert
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
amgebauer
</td>
</tr>
</table>
<pre>
I get a Segmentation fault when analyzing the following code with clang-tidy 17.0.2 with the check `modernize-loop-convert` in about 50% of the runs:
test.cpp:
```c++
template <unsigned int p> void test() {
unsigned int test[3][3 * p];
// Initialize to zero
for (unsigned int i = 0; i < 3 * p; ++i)
for (unsigned int j = 0; j < 3; ++j)
test[j][i] = 0;
}
```
by running `clang-tidy test.cpp -checks=modernize-loop-convert`.
In around 50% of the cases, I get the following error:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/gebauer/programs/clang-tidy-17.0.2/usr/local/bin/clang-tidy test.cpp -checks=modernize-loop-convert
1. <eof> parser at end of file
2. ASTMatcher: Processing 'modernize-loop-convert' against:
ForStmt : </home/gebauer/work/baci/test/test.cpp:6:5, line:7:20>
--- Bound Nodes Begin ---
conditionBound - { ImplicitCastExpr : </home/gebauer/work/baci/test/test.cpp:6:34> }
forLoopArray - { ForStmt : </home/gebauer/work/baci/test/test.cpp:6:5, line:7:20> }
initVar - { VarDecl j : </home/gebauer/work/baci/test/test.cpp:6:10, col:27> }
--- Bound Nodes End ---
#0 0x00005590c08d407f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/gebauer/programs/clang-tidy-17.0.2/usr/local/bin/clang-tidy+0x453207f)
#1 0x00005590c08d1af4 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f36de74d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00005590bf6deb5a clang::ASTContext::getTypeInfo(clang::Type const*) const (/home/gebauer/programs/clang-tidy-17.0.2/usr/local/bin/clang-tidy+0x333cb5a)
#4 0x00005590bf6f270f clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/home/gebauer/programs/clang-tidy-17.0.2/usr/local/bin/clang-tidy+0x335070f)
#5 0x00005590bf6deca5 clang::ASTContext::getTypeInfo(clang::Type const*) const (/home/gebauer/programs/clang-tidy-17.0.2/usr/local/bin/clang-tidy+0x333cca5)
[...]
#254 0x00005590bf6f270f clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/home/gebauer/programs/clang-tidy-17.0.2/usr/local/bin/clang-tidy+0x335070f)
#255 0x00005590bf6deca5 clang::ASTContext::getTypeInfo(clang::Type const*) const (/home/gebauer/programs/clang-tidy-17.0.2/usr/local/bin/clang-tidy+0x333cca5)
Segmentation fault (core dumped)
```
For the other 50% of the runs, I get the expected result:
```
1 warning generated.
/home/gebauer/work/baci/test/test.cpp:6:5: warning: use range-based for loop instead [modernize-loop-convert]
6 | for (unsigned int j = 0; j < 3; ++j)
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| (auto & j : test)
7 | test[j][i] = 0;
| ~~~~~~~
| j
```
I'm running this on Ubuntu 20.04.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV8tu67wRfhp6M5BAk7rYCy98idEAf4sDJP23AUWNZCYyKZDUyWXRZy9I2bGdOj3tuaDoCZxYVIZz-b4ZckY4p1qNuCD5iuSbiRj8ztiF2LdYiQHtpDL16-IWWvQg4A7bPWovvDIaGjF0Hp53qEFo0b2-Kd2C3yE0puvMc1hJUyM8K78D2QndJl7VrzAtU5qy8XUQlzuUT0AKujc1Wq3eMOmM6RNp9Fe0nhQUlAZRmcFDTgnLwTRxox20I3xJ6IbQw1-Pzqey70-vCzp-JGGr8DmI7ftOeATC14OOCNSgtIee8Bv4alQNQRNhM8LmQMrDNoAL4SiSrzjJN-ELCFtCHxZ8de4TAGFbwrZ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