[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 Dec 23 22:43:56 PST 2019


liufengdb updated this revision to Diff 235202.
liufengdb added a comment.

Use the first location in the fused location for diagnostic handler

A new utility method is created to find out the first CallSiteLoc to display the stack.


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


Index: mlir/lib/IR/Diagnostics.cpp
===================================================================
--- mlir/lib/IR/Diagnostics.cpp
+++ mlir/lib/IR/Diagnostics.cpp
@@ -373,6 +373,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 CallSiteLocation from the given location.
+static Optional<FileLineColLoc> 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;
   }
@@ -442,13 +458,13 @@
 
   // 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();
+      if (auto subLoc = callerLoc.dyn_cast<CallSiteLoc>())
+        callerLoc = subLoc.getCaller();
       else
         break;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71851.235202.patch
Type: text/x-patch
Size: 1799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191224/55f1c97e/attachment.bin>


More information about the llvm-commits mailing list