<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154812>154812</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang-tidy invalid suggestion: misc-static-assert -fix -fix-errors
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
joker-eph
</td>
</tr>
</table>
<pre>
```
$ clang-tidy -p build mlir/lib/IR/BuiltinAttributes.cpp --checks=-*,misc-static-assert -fix -fix-errors
```
Suggests:
```
diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp
index 6f880f810d65..a60dca5b85e8 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -482,7 +482,7 @@ static bool getBit(const char *rawData, size_t bitPos) {
/// BE format.
static void copyAPIntToArrayForBEmachine(APInt value, size_t numBytes,
char *result) {
- assert(llvm::endianness::native == llvm::endianness::big);
+ static_assert(llvm::endianness::native == llvm::endianness::big);
assert(value.getNumWords() * APInt::APINT_WORD_SIZE >= numBytes);
// Copy the words filled with data.
@@ -511,7 +511,7 @@ static void copyAPIntToArrayForBEmachine(APInt value, size_t numBytes,
/// format.
static void copyArrayToAPIntForBEmachine(const char *inArray, size_t numBytes,
APInt &result) {
- assert(llvm::endianness::native == llvm::endianness::big);
+ static_assert(llvm::endianness::native == llvm::endianness::big);
assert(result.getNumWords() * APInt::APINT_WORD_SIZE >= numBytes);
// Copy the data that fills the word of `result` from `inArray`.
@@ -1401,7 +1401,7 @@ void DenseIntOrFPElementsAttr::convertEndianOfCharForBEmachine(
using llvm::support::ulittle32_t;
using llvm::support::ulittle64_t;
- assert(llvm::endianness::native == llvm::endianness::big);
+ static_assert(llvm::endianness::native == llvm::endianness::big);
// NOLINT to avoid warning message about replacing by static_assert()
// Following std::copy_n always converts endianness on BE machine.
```
Unfortunately this does not compile: the assert is meant to fail dynamically.
The name of the API is `copyAPIntToArrayForBEmachine` ; it will only be called on big-endian machine, and the assert is ensuring this.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0lt-PmzgQx_8a52VEZMyPJQ95IMlGinTaXbV7qnQvKwMG3Bob2UNS7q8_GbJJulWrrXQroYTYzMx3Zj4xw52TjRZiTZINSXYLPmBr7Pqr-SZsIPp2UZhqXJOUni-aExZDqbhuApTVCEEPxSBVBZ2SlrC9kgVh-8MnwvabQSqUOke0shhQuGXZ9xAEZSvKb45Eu4CwnLBtJ10ZOOQoy4A7JyxCUMvv00cgrDXW-bi3Gmj-eWga4dCRKJ8XbvcrWdcQBI1E4ITt3yuteP-zhOZSV-I7pHWW0ToLaZUmyyVPaVXypMgSkUFIaRrHhOZBEPyJjqnIm_n6Q00kpiSmEMQZI2x7B4RtLrfz1lxnKIxR0AjcSCQsK412CGXLLRCWW37aceSEbcHJf8ULQiHxyTjCVkDuNoTmQNh-vmBzD7WxHcelXz97PxpZQWn6MX86aHw2ubV83Bu7ue942UotCMumLThyNYibSHroNiMKR9jW-7tIEm5QeBUQAMykEJYpdew8BVEudCW51sK5-bfmKI8CSLQj0Q5-_VwhG8JWJNrMlYdzGi8fFAJuxE_5LxuBD0P3xdjKEZZNabIcpgrN5vnT4eH55cvjp93L58M_90Ciex_vWq1X17P7c2-2ph8BWwEn7xlqqZSo4CSxhYojX94Ak4ThKzCX2x-A-d9aekXnd9x4789mcvgmyI-sSj09-utwsybC0p8R-kCCPhigi985qQ_nx9MC2HKcGHIXpsDUQFJ6Lm1Kobam8yuvbUnpLWRhTC-UXe_nzan1O6GdOGh8tPuneyU6odH5M25OojT6KCzeT5V5rLctt2_Y8OoHJ3VzU0g39L2x5zoMSiIqEbEXvPwX32OQxheDDz99PvzwOXf34fGvw8MzoAE-Ff_ErfaV6IRzvBHACzMgWNErXvr1YvxJmvf6Fpq9UcqcvIHD6rVx_fi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