[PATCH] D71851: Use the first location in the fused location for diagnostic handler

Feng Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 09:46:15 PST 2020


liufengdb updated this revision to Diff 243603.
liufengdb added a comment.
Herald added subscribers: Joonsoo, aartbik.

Use the first location in the fused location for diagnostic handler


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71851/new/

https://reviews.llvm.org/D71851

Files:
  mlir/lib/IR/Diagnostics.cpp
  mlir/test/IR/diagnostic-handler.mlir


Index: mlir/test/IR/diagnostic-handler.mlir
===================================================================
--- /dev/null
+++ mlir/test/IR/diagnostic-handler.mlir
@@ -0,0 +1,13 @@
+// RUN: not mlir-opt %s -o - 2>&1 | FileCheck %s
+// This test verifies that diagnostic handler can emit the call stack successfully.
+
+// -----
+
+// emit the first call stack in the fused location.
+func @constant_out_of_range() {
+  // CHECK: mysource1: error: 'std.constant' op requires attribute's type ('i64') to match op's return type ('i1')
+  // CHECK-NEXT: mysource2: note: called from
+  // CHECK-NEXT: mysource3: note: called from
+  %x = "std.constant"() {value = 100} : () -> i1 loc(fused[callsite("foo"("mysource1":0:0) at callsite("mysource2":1:0 at "mysource3":2:0)), "bar"])
+  return
+}
\ No newline at end of file
Index: mlir/lib/IR/Diagnostics.cpp
===================================================================
--- mlir/lib/IR/Diagnostics.cpp
+++ mlir/lib/IR/Diagnostics.cpp
@@ -374,6 +374,22 @@
   case StandardAttributes::CallSiteLocation:
     // Process the callee of a callsite location.
     return getFileLineColLoc(loc.cast<CallSiteLoc>().getCallee());
+  case StandardAttributes::FusedLocation:
+    return getFileLineColLoc(loc.cast<FusedLoc>().getLocations().front());
+  default:
+    return llvm::None;
+  }
+}
+
+/// Return a processable CallSiteLoc from the given location.
+static Optional<CallSiteLoc> getCallSiteLoc(Location loc) {
+  switch (loc->getKind()) {
+  case StandardAttributes::NameLocation:
+    return getCallSiteLoc(loc.cast<NameLoc>().getChildLoc());
+  case StandardAttributes::CallSiteLocation:
+    return loc.cast<CallSiteLoc>();
+  case StandardAttributes::FusedLocation:
+    return getCallSiteLoc(loc.cast<FusedLoc>().getLocations().front());
   default:
     return llvm::None;
   }
@@ -443,15 +459,15 @@
 
   // If the diagnostic location was a call site location, then print the call
   // stack as well.
-  if (auto callLoc = loc.dyn_cast<CallSiteLoc>()) {
+  if (auto callLoc = getCallSiteLoc(loc)) {
     // Print the call stack while valid, or until the limit is reached.
-    Location callerLoc = callLoc.getCaller();
+    Location callerLoc = callLoc->getCaller();
     for (unsigned curDepth = 0; curDepth < callStackLimit; ++curDepth) {
       emitDiagnostic(callerLoc, "called from", DiagnosticSeverity::Note);
-      if ((callLoc = callerLoc.dyn_cast<CallSiteLoc>()))
-        callerLoc = callLoc.getCaller();
-      else
+      callLoc = getCallSiteLoc(callerLoc);
+      if (!callLoc)
         break;
+      callerLoc = callLoc->getCaller();
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71851.243603.patch
Type: text/x-patch
Size: 2623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200210/6c740023/attachment.bin>


More information about the llvm-commits mailing list