<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66975>66975</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`__builtin_dynamic_object_size` mode 1 falls back to mode 0 when array index is not a constant expression
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kees
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/MaEG8eEMd
For a struct like this:
```
struct suspend_stats {
int failed_resume_noirq;
#define REC_FAILED_NUM 2
int last_failed_dev;
char failed_devs[REC_FAILED_NUM][40];
int last_failed_errno;
int bar;
};
```
`__bdos(x, 1)` should match `sizeof(x)` for the multidimensional array. When the array index is a constant expression, this works correctly. If it's not, it breaks:
```
argc == 1
__builtin_dynamic_object_size(foo.failed_devs[1], 1) == sizeof(foo.failed_devs[1])
__builtin_dynamic_object_size(foo.failed_devs[argc], 1) != sizeof(foo.failed_devs[1]) !!!
```
The first `bdos` is correct, the second is not.
@nickdesaulniers @isanbard
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE2P5CYQ_TX4UtoWxm33-ODDzPY4WimTQ5QoR4uPcpttDBMK78zsr49we-drNx-KhUDA4xW8Vy5JZE8esWP1DauPhVzSFGJ3RqRCBfPUTSndE6uumeiZ6E_BqODSLsQTE_1XJvo7efvTFd7eGcaPjF9f-j5EkEApLjqBs2eENNmV5RWINXxr63RD00L36M1ASSYCdri57ML2WZ9glNahGSLSMuPgg41_smrDMVEZHK1H-PX249Bff_r59jj88vsdgPieyElKw8Zm8MszyTeMnmTM4wuEWH3zlpjVR1bf7Hken89n8vy9DoAx-vBdiIxUMr7c__BC806g58VhUCYQE1ePTHyEkomWNRxoCoszMMukJ2ANJ_sVw3hBrYAxREgTwry4ZI2d0ZMNXjqQMcqnHfwxoV8B6xysN_gIlkCCDp6S9Anw8T4i5WM5cvYUHkI8E-gQI-rknnbwaQSbmDgQ-JAyzCZQEeX5X_wHABlPGlh1ZNURym11GNRiXbJ-ME9ezlYPQX1GnYb8PiauxhB2b_0psxWbMN_YnsX4O3j7v8PlS7-OCEyU_y3kiry0Hwny24Qw2kgpu7k63vDsx6b1xQEEQh28yRs-pN0bgffcW302SHJx3mIkYHtuSXolo4HCdJVpq1YW2JVNW4umrZqymLpKKSH0oapbXSqtZVNyXVaHUgpVtWVjCtsJLireipLvc7_je1W2oir1VdsYbVq25zhL63bOfZlzsSgs0YJd07SHunBSoaO14gjh8QHWTSZELkCxy2c-qOVEbM-dpUQvLMkmh93lF_gHmxoOczAIJYzSOQIl9RlSuCxyeMiJ_i7JfUg_TvRiie59EbRpWtROh5mJPt9tGz7cx_B5daZfX0RM9OuL_woAAP__106l7A">