<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60674>60674</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
__array_extent is generating the wrong value in runtime contexts
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:codegen
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cjdb
</td>
</tr>
</table>
<pre>
```cpp
#include <iostream>
#include <type_traits>
template<class T>
[[nodiscard]] constexpr auto f(T&& t)
{
return __array_extent(std::remove_reference_t<T>, 0);
}
int main()
{
int x[] = {0, 1, 2, 3};
std::cout << f(x) << '\n';
}
```
The above program should print out `4`, but it gives a garbage result at the moment. I'm struggling to get a compile-time constant out of this minimalish repro, but when when I can get that, the value seems to be correct at both compile- and run-time.
https://godbolt.org/z/7oPd1Y8Mv
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsU8GOozgQ_ZriUurImADJgUMn2UhzWGkPfdlTVEAFPDI2sotMer9-ZdKZ7t0ZCZWxXPXeq1c2xWgGx9xAeYDylNEiow9N971vs9b37w1U6vF18wzqBOoVdGFcZ5eeEYqj8VEC0wTFH787lveZLxLISPzMWKPwNFsShuLYWYoR3z4TkpaD872JHYUeyhOUJ-y8i8L3OSAt4vEKevcGugJdoYDef5TWh8cPImJgWYLDy4VCoPcL34WdgN5F6aF4heI18ORvfAl85cCu44tAcVx16COqBFocnrinr-KNE5zIONC731OnhPvDU4TihFAfVALNU9ApFAmy-FLyU1XnF0neQXFcu7yD3j_3oGsojy4tv0p7juqr0reRkVp_Y5yDHwJNGEe_2B7nkDSuVJXapip9xHYRNIKDuXFEwoFCSwNj4LhYQRKUkXHyEzvZ4DfQ9YRRwjIM1rgBxePAgoSdn2Zj-UXMxI-50QeXv6KMJuJknJnImjhi4Dn4J_mPkd0jfMOO3IonI0k6T9w3sgtjZJ5iomsTfAjcreJaL-NPbiTXY1jcKmLz1ZJRZI7Jan0GfR5833orGx8G0Od_QJ9r_1ef_73785b1TdHviz1l3ORVXal9npdVNjYt7a6dUqW-bnf9rqyuJVPeqV7V-qquuc5Mo5UulM5ztS11UW0U73c15RXpvtzn-xq2iicydmPtbUrcmYlx4aZSVb3NLLVs4_omte4suWG9Fj0P7EDr9FBDkypf2mWIsFXWRImfWGLEcvPfe48m4sCOA8k6q5HxR_Bu-LDUuGTWc2DCd4nZEmzzP7OMjEu76fwE-pzoPpaXOfjv3Ano89pHBH1eW_k3AAD__82aVYw">