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 @@ -89,9 +89,11 @@ // Allocate memory to hold this string. SmallString<64> data; auto strRef = val.toStringRef(data); + if (strRef.empty()) + return strRef; + strings.push_back(std::unique_ptr(new char[strRef.size()])); memcpy(&strings.back()[0], strRef.data(), strRef.size()); - // Return a reference to the new string. return StringRef(&strings.back()[0], strRef.size()); }