<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154790>154790</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang-tidy invalid suggestion: llvm-prefer-isa-or-dyn-cast-in-conditionals
</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>
With clang-tidy built at current head and applying it on MLIR:
```
$ clang-tidy -p build mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp --checks=-*,llvm-prefer-isa-or-dyn-cast-in-conditionals -fix -fix-errors
```
Yield:
```
diff --git a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
index 17371ecb79e7..20acd9110104 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
@@ -234,7 +234,7 @@ ROCDLTargetAttr::verify(function_ref<InFlightDiagnostic()> emitError,
return failure();
}
if (files && !llvm::all_of(files, [](::mlir::Attribute attr) {
- return attr && mlir::isa<StringAttr>(attr);
+ return isa_and_nonnullr::isa<StringAttr>(attr);
})) {
emitError() << "All the elements in the `link` array must be strings.";
return failure();
```
Something went bad in the rewriting: `isa_and_nonnullr::isa<` instead of `isa_and_nonnull<` here.
Another similar case:
```
$ clang-tidy -p build mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp --checks=-*,llvm-prefer-isa-or-dyn-cast-in-conditionals -fix -fix-errors
```
```
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
index 2ba6106896c1..44fb47f74ccc 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
@@ -173,7 +173,7 @@ LogicalResult spirv::InterfaceVarABIAttr::verifyInvariants(
return emitError() << "expected 32-bit integer for binding";
if (storageClass) {
- if (auto storageClassAttr = llvm::cast<IntegerAttr>(storageClass)) {
+ if (auto storageClassAttr = dyn_cast::cast<IntegerAttr>(storageClass)) {
auto storageClassValue =
spirv::symbolizeStorageClass(storageClassAttr.getInt());
if (!storageClassValue)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8lk1v4zgPxz-NciEUyLJjJ4cc3GQCBOjgedAuuthTIdu0zRlFDiS5M9lPv5Cdt8m8tV1gAyOVS-pPihR_iHKOGoO4ZLM7NltPVO_bzi4_dZ_Rcty3k6KrDss_ybdQamUa7qk6QNGT9qA8lL21aDy0qCpQpgK13-sDmQbIQ2fg4_32gcU5E6cnFcdH5Ewm15p8P8hWsNNkmdxoKpjcrElpLD2Tm_v7p4_bByY3w9fD_1br-6NxWu73wHnZYvnZsXjNmcyZXGn9suN7izVaTk7xzvLqYHipnOdkeNmZijx1RmkHvKavwxdHazvrblMV-V-Euroc5cpYUV0D5w15UExu3pd-8d6dTORkKvwKURZnEZZFtsBsOpVCldUiikQkEoiESJOEiZxz_v4ch5bdjc-_ypclgiUCuIwTJlcZMHl3Xo6mYdMfyjboc-9tKHucv6Cl-sDkvO5NGRr3bLFm8WprNpqa1q9JNaZznkom50wuWPwBcEf-Q-gokysmcrDoe2ugVqR7iye_u2ACYNl6XFANIQxpdMBkymQKTEbhPo2ZKK2fu_rkwuQKxukJeoPDUJlhFdKnovcIKhxELoBlIRyH4-eYUbCeYl12k1MsXj16S6YZC_GByflRacw7NONbKXLqWZnq2XTG9Fq_XuooE8ogF5dUh39eFXI-mOIVi1fApMy1Bt8ioMYdGu-AzPDOUqHJfGapAGWtOsCudx4KBDfk4KZMyqu4P-_MzSA-djv0bUDMl0CeQlWniBa_WPJkGhbnIfyvChHSIuN84FZX_8D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