[Mlir-commits] [mlir] 8815c50 - [MLIR] Allow setting call stack limit for SourceMgrDiagnosticHandler (#123373)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Jan 17 09:59:23 PST 2025


Author: JoelWee
Date: 2025-01-17T17:59:18Z
New Revision: 8815c505be90edf0168e931d77f2b68e393031d3

URL: https://github.com/llvm/llvm-project/commit/8815c505be90edf0168e931d77f2b68e393031d3
DIFF: https://github.com/llvm/llvm-project/commit/8815c505be90edf0168e931d77f2b68e393031d3.diff

LOG: [MLIR] Allow setting call stack limit for SourceMgrDiagnosticHandler (#123373)

Otherwise for deeply nested code, the callstack will always be truncated

Added: 
    

Modified: 
    mlir/include/mlir/IR/Diagnostics.h
    mlir/lib/IR/Diagnostics.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h
index 8429325412dc97..36c433c63b26d1 100644
--- a/mlir/include/mlir/IR/Diagnostics.h
+++ b/mlir/include/mlir/IR/Diagnostics.h
@@ -578,6 +578,9 @@ class SourceMgrDiagnosticHandler : public ScopedDiagnosticHandler {
   void emitDiagnostic(Location loc, Twine message, DiagnosticSeverity kind,
                       bool displaySourceLine = true);
 
+  /// Set the maximum depth that a call stack will be printed. Defaults to 10.
+  void setCallStackLimit(unsigned limit);
+
 protected:
   /// Emit the given diagnostic with the held source manager.
   void emitDiagnostic(Diagnostic &diag);
@@ -605,7 +608,6 @@ class SourceMgrDiagnosticHandler : public ScopedDiagnosticHandler {
   std::optional<Location> findLocToShow(Location loc);
 
   /// The maximum depth that a call stack will be printed.
-  /// TODO: This should be a tunable flag.
   unsigned callStackLimit = 10;
 
   std::unique_ptr<detail::SourceMgrDiagnosticHandlerImpl> impl;

diff  --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 7eb3d5bcd07f19..19b32120f58905 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -519,6 +519,10 @@ void SourceMgrDiagnosticHandler::emitDiagnostic(Diagnostic &diag) {
   }
 }
 
+void SourceMgrDiagnosticHandler::setCallStackLimit(unsigned limit) {
+  callStackLimit = limit;
+}
+
 /// Get a memory buffer for the given file, or nullptr if one is not found.
 const llvm::MemoryBuffer *
 SourceMgrDiagnosticHandler::getBufferForFile(StringRef filename) {


        


More information about the Mlir-commits mailing list