<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/225041>225041</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] __builtin_object_size with an out-of-range type argument is not rejected inside _Static_assert / enum and asserts in the constant evaluator
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
captainnemo9292
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/MnTvfYoYP (`-O0`)
```c
_Static_assert(__builtin_object_size((void*)0, 4), "");
```
```
clang: clang/lib/AST/ExprConstant.cpp:17034: bool {anonymous}::IntExprEvaluator::VisitBuiltinCallExpr(const clang::CallExpr*, unsigned int): Assertion `Type <= 3 && "unexpected type"' failed.
#10 (anonymous namespace)::IntExprEvaluator::VisitBuiltinCallExpr(clang::CallExpr const*, unsigned int)
#13 Evaluate(...)
#15 CheckEvalInICE(clang::Expr const*, clang::ASTContext const&)
#16 CheckICE(clang::Expr const*, clang::ASTContext const&)
#18 clang::Expr::isIntegerConstantExpr(clang::ASTContext const&) const
#19 clang::Sema::VerifyIntegerConstantExpression(...)
#21 clang::Sema::BuildStaticAssertDeclaration(...)
```
In an ordinary context the type argument is range-checked: `int x = __builtin_object_size((void*)0, 4);` gives `argument value 4 is outside the valid range [0, 3]`. Inside `_Static_assert` (or an enumerator initializer) that check does not fire and the ICE check evaluates the call with type 4, which the evaluator only asserts on. Clang trunk, assertions build.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVU2P4jgQ_TXFpURkKiSQA4dANxKH1a7UrZXmhBynAM8YG8UO08yvX9mB_qB7DiOtFAmLsl_Ve6_Klt7rvWVeQLGE4mEk-3Bw3ULJU5DaWj66iioaNa69LA4hnDzkNdAaaL13beNMyFy3B1r_Alr_ZZ_Pu2_u2z8INIdSjP8WUAqgCkQdv1IMnwJRb5-CDFptpffcBaD5dtv02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