<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/145218>145218</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
No warning about dangerous pointer casts
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wo4mei3
</td>
</tr>
</table>
<pre>
Both Clang and GCC do not issue any warnings about the following code, even with the -Wall option.
For Clang, I used Clang-16.
The executable produced by GCC caused a segmentation fault, while Clang's always prints 1.
I propose that casting a pointer from a smaller pointee type to larger one, which can easily lead to segmentation faults should produce a compiler warning.
```
#include <stdio.h>
struct X {
int x;
};
struct Y {
int x;
int y;
};
int main(void) {
struct X x = {0};
struct Y* y = (struct Y*) &x;
y->y = 1;
printf("%d", y->y);
return 0;
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxkU0GvozgM_jXhYrWCAAUOHPra6Woue1ppd44mcSGrkKAktI9_Pwqlnc4bFCnB_vz5c2Kj96o3RC0rP1h5TnAOg3Xt3RYjqTzprFzaDxsGOGk0PaCR8NfpBNKCsQGU9zMBmgXu6IwyvQfs7BwgDARXq7W9K9ODsJIYPwHdyMBdhWH17_5FrcFOQVmzZ-nxYt0jS4R-h9mTfPzvskP0_zMQ0CeJOWCnCSZn5SxIQreskgSuEQie-pFMwMgLV5x1iIT3QWl68lceUN9x8TA5ZYKHLCb4Hjkn6wnCgAEE-hDVI0xWmUAOrs6OMcGIWpPbzARhmQiCBY2uJwfW0JZQDCDQAKFXegFNKCPsT30e_GBnLZ81AYKw46Riku1io764Dum20iPjuTJCz5KA5ScfpLL7geXfHkgf3CwC_Aes-mDpEZQJ8MnyeGbVeTu8YD-esO17Q7-blj8JonlEZRivb1ZJxpsvVC8hn8Dyc3Smr_gvmB-MH2F5wHj9ZlxZ-eGLomXH8m8PePa7Z33VK-M145zxUq7baQtgvPkd7SjMzkD6q7i3i05km8smbzChNqvKtKxqXvNkaElkTUaipvIqmjqnRhS8qa9dKkqBlTwkquUpL9MD52lVFAXfp10uu4qySmKZHuoDK1IaUem91rdxb12frPPUZkXJszrR2JH262Bybuj-mLZYSnlOXBuDdt3ce1akWvngf9EEFTS1f9tn82xDKdH05OzsXw0dW9wns9PtEMLkWX5k_ML4pVdhmLu9sCPjl0i7bbvJ2f9JBMYvqxjP-GVTe2v5zwAAAP__9VBSBQ">