From 84bc22ed7336b4ddba90b89673500afd5ce19494 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 9 Dec 2024 17:25:22 -0600 Subject: [PATCH] DiagnosticPrinter: Use printAsOperand to handle anonymous values To avoid changing the behavior in the general case, only do this for anonymous functions. Otherwise, we'll end up with a leading '@' on the name, which may not be meaningful to end users. --- llvm/lib/IR/DiagnosticPrinter.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/DiagnosticPrinter.cpp b/llvm/lib/IR/DiagnosticPrinter.cpp index 49b8bbae53be9..5ded23403b41e 100644 --- a/llvm/lib/IR/DiagnosticPrinter.cpp +++ b/llvm/lib/IR/DiagnosticPrinter.cpp @@ -97,7 +97,12 @@ DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Twine &Str) { // IR related types. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Value &V) { - Stream << V.getName(); + // Avoid printing '@' prefix for named functions. + if (V.hasName()) + Stream << V.getName(); + else + V.printAsOperand(Stream, /*PrintType=*/false); + return *this; }