[Mlir-commits] [mlir] [mlir][LLVMIR] Bound import diagnostics and share one slot tracker (PR #229956)
Tobias Gysi
llvmlistbot at llvm.org
Wed Oct 7 22:02:25 PDT 2026
================
@@ -52,25 +53,61 @@ using namespace mlir::LLVM::detail;
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsFromLLVM.inc"
-// Utility to print an LLVM value as a string for passing to emitError().
-// FIXME: Diagnostic should be able to natively handle types that have
-// operator << (raw_ostream&) defined.
-static std::string diag(const llvm::Value &value) {
+/// Upper bound on the characters a diagnostic renders for an LLVM entity.
+/// One rendering is unbounded by nature: a GlobalVariable prints its entire
+/// initializer, and a node with long MDStrings or large inline constants
+/// prints them whole. On a merged library a single unbounded diagnostic
+/// reaches tens of megabytes, so every rendering path below truncates its
+/// output. Diagnostics only need to identify the entity; the full form is
+/// in the input being imported.
+static constexpr size_t kMaxDiagLength = 256;
+
+static std::string truncateDiag(std::string str) {
+ if (str.size() <= kMaxDiagLength)
+ return str;
+ str.resize(kMaxDiagLength);
+ str += "... <truncated>";
+ return str;
+}
+
+// Prints a metadata node through a caller-provided tracker so module-flag
+// conversion shares the importer's tracker instead of building one per call.
----------------
gysit wrote:
```suggestion
/// Prints a metadata node through a caller-provided tracker so module-flag
/// conversion shares the importer's tracker instead of building one per call.
```
ultra nit:
https://github.com/llvm/llvm-project/pull/229956
More information about the Mlir-commits
mailing list