Skip to content

DiagnosticPrinter: Use printAsOperand to handle anonymous values #119491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Dec 11, 2024

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.

@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2024

@llvm/pr-subscribers-backend-arm
@llvm/pr-subscribers-backend-amdgpu
@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/119491.diff

1 Files Affected:

  • (modified) llvm/lib/IR/DiagnosticPrinter.cpp (+6-1)
diff --git a/llvm/lib/IR/DiagnosticPrinter.cpp b/llvm/lib/IR/DiagnosticPrinter.cpp
index 49b8bbae53be9e..5ded23403b41e6 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;
 }
 

@arsenm arsenm marked this pull request as ready for review December 11, 2024 03:20
Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test?

@arsenm
Copy link
Contributor Author

arsenm commented Dec 11, 2024

can you add a test?

See next up the stack

Copy link
Contributor Author

arsenm commented Dec 11, 2024

Merge activity

  • Dec 11, 3:11 AM EST: A user started a stack merge that includes this pull request via Graphite.
  • Dec 11, 3:16 AM EST: Graphite rebased this pull request as part of a merge.
  • Dec 11, 3:19 AM EST: A user merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/diagnostic-info-cleanup-dk-inlineasm branch from dff095d to 1619481 Compare December 11, 2024 08:13
Base automatically changed from users/arsenm/diagnostic-info-cleanup-dk-inlineasm to main December 11, 2024 08:16
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.
@arsenm arsenm force-pushed the users/arsenm/diagnostic-printer-use-print-as-operand branch from 8bfb4bd to 84bc22e Compare December 11, 2024 08:16
@arsenm arsenm merged commit 1bc1703 into main Dec 11, 2024
5 of 7 checks passed
@arsenm arsenm deleted the users/arsenm/diagnostic-printer-use-print-as-operand branch December 11, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants