diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -466,7 +466,7 @@ SmallVector> locationStack; auto addLocToStack = [&](Location loc, StringRef locContext) { if (Optional showableLoc = findLocToShow(loc)) - locationStack.emplace_back(loc, locContext); + locationStack.emplace_back(showableLoc.getValue(), locContext); }; // Add locations to display for this diagnostic. @@ -489,7 +489,9 @@ // If the location stack is empty, use the initial location. if (locationStack.empty()) { - emitDiagnostic(diag.getLocation(), diag.str(), diag.getSeverity()); + if (Optional showableLoc = findLocToShow(diag.getLocation())) { + emitDiagnostic(showableLoc.getValue(), diag.str(), diag.getSeverity()); + } // Otherwise, use the location stack. } else { diff --git a/mlir/test/IR/diagnostic-handler-filter.mlir b/mlir/test/IR/diagnostic-handler-filter.mlir --- a/mlir/test/IR/diagnostic-handler-filter.mlir +++ b/mlir/test/IR/diagnostic-handler-filter.mlir @@ -11,7 +11,7 @@ // ----- // CHECK-LABEL: Test 'test2' -// CHECK-NEXT: mysource1:0:0: error: test diagnostic +// CHECK-NOT: mysource1:0:0: error: test diagnostic func private @test2() attributes { test.loc = loc("mysource1":0:0) }