<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78841>78841</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang crashes when generating a reference of auto type from a nullptr casted to a pointer to an integer array of unknown size
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ChipsSpectre
</td>
</tr>
</table>
<pre>
Extension from https://github.com/llvm/llvm-project/issues/76634, since below the surface of that issue's crash problem there is another issue causing a crash of clang.
Consider this code, simplified from 76634:
```
int main() {
int m = 1;
auto& x = *(int(*)[m])(nullptr);
return x[0];
}
```
Compiling this with the latest version of clang will trigger the following assertion:
> clang-18: /home/drives/fastSSD/llvm-project/clang/include/clang/AST/Type.h:753: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.
Because in ExprConstant.cpp.9275, the dynamic cast to a ConstantArrayType fails and clang tries to add an unsized array to the result.
If we add a check for a nullptr at this position (and return false in that case), several test cases in test/clang/AST/Interp/arrays.cpp (line 500) fail since the diagnostic errors for incomplete arrays are not emitted. For example, the _must be initialized by a constant expression_ diagnostic.
At which point in the clang AST parsing can we add the check for _must be initialized by a constant expression_, which should trigger when we try to perform the cast to a pointer to an integer array of unknown size?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVU2P2zYQ_TX0ZRBDpj4sH3zQrtdAgCBosek5oKmRxYYiBXK0tvvriyHtTYL0EhQwZJF6HM6898hRMZqzQ9yL-knUh5VaaPRh_zyaOb7OqCng6uT72_7lSuii8Q6G4CcYieYoyk7Io5DHs6FxOa21n4Q8Wvv2-PswB_83ahLyaGJcMAp53DZNWQn5DNE4jXBC6y9AI0JcwqA0gh-ARkWQVgi5jaCDiiPMwZ8sTowNCCaCcp7fMxC0WqJxZ1B3uB9AW-XOa1EcR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