[Mlir-commits] [mlir] [mlir] Avoid crash in mlir-query by using dyn_cast instead of cast for FileLineColLoc (PR #145049)
Jacques Pienaar
llvmlistbot at llvm.org
Fri Jun 20 08:17:57 PDT 2025
================
@@ -38,21 +38,23 @@ MatchFinder::collectMatches(Operation *root, DynMatcher matcher) const {
void MatchFinder::printMatch(llvm::raw_ostream &os, QuerySession &qs,
Operation *op) const {
- auto fileLoc = cast<FileLineColLoc>(op->getLoc());
- SMLoc smloc = qs.getSourceManager().FindLocForLineAndColumn(
- qs.getBufferId(), fileLoc.getLine(), fileLoc.getColumn());
- llvm::SMDiagnostic diag =
- qs.getSourceManager().GetMessage(smloc, llvm::SourceMgr::DK_Note, "");
- diag.print("", os, true, false, true);
+ if (auto fileLoc = dyn_cast<FileLineColLoc>(op->getLoc())) {
----------------
jpienaar wrote:
How about using
```
auto fileLoc = op->getLoc()->findInstanceOf<FileLineColLoc>()
```
?
Although I can't see relates to the failure case. Could you check for it what the op is and getLoc() is?
https://github.com/llvm/llvm-project/pull/145049
More information about the Mlir-commits
mailing list