[llvm] Emit newline after IR-dump banner in PrintCallGraphPass (PR #199410)

Prerona Chaudhuri via llvm-commits llvm-commits at lists.llvm.org
Mon May 25 10:34:57 PDT 2026


https://github.com/pchaudhuri-nv updated https://github.com/llvm/llvm-project/pull/199410

>From ef713f4bc83aa902210fd07450e95172df6c9dd5 Mon Sep 17 00:00:00 2001
From: pchaudhuri-nv <pchaudhuri at nvidia.com>
Date: Sun, 24 May 2026 09:14:19 +0000
Subject: [PATCH] Emit newline after IR-dump banner in PrintCallGraphPass

Required for Compiler Explorer's opt-pipeline viewer: the tool parses
pass output by splitting on the IR-dump banner line, so the banner must
end with a newline. Without it, targets that exercise this pass cannot
be inspected through the opt-pipeline feature.

Assisted by Claude.
---
 llvm/lib/Analysis/CallGraphSCCPass.cpp    |  2 +-
 llvm/unittests/Analysis/CallGraphTest.cpp | 32 +++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp
index 9213ea8ea2383..3fd2fe02f6688 100644
--- a/llvm/lib/Analysis/CallGraphSCCPass.cpp
+++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp
@@ -678,7 +678,7 @@ namespace {
       auto PrintBannerOnce = [&]() {
         if (BannerPrinted)
           return;
-        OS << Banner;
+        OS << Banner << "\n";
         BannerPrinted = true;
       };
 
diff --git a/llvm/unittests/Analysis/CallGraphTest.cpp b/llvm/unittests/Analysis/CallGraphTest.cpp
index 566733f10c8a9..589f52d198bd1 100644
--- a/llvm/unittests/Analysis/CallGraphTest.cpp
+++ b/llvm/unittests/Analysis/CallGraphTest.cpp
@@ -7,9 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/CallGraph.h"
+#include "llvm/Analysis/CallGraphSCCPass.h"
+#include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
+#include <memory>
 
 using namespace llvm;
 
@@ -57,4 +61,32 @@ TEST(CallGraphTest, GraphTraitsConstSpecialization) {
 
   canSpecializeGraphTraitsIterators(const_cast<const CallGraph *>(&CG));
 }
+
+TEST(CallGraphTest, PrintCallGraphPassBannerEndsWithNewline) {
+  LLVMContext Context;
+  Module M("CallGraphTest", Context);
+  IRBuilder<> Builder(Context);
+  Function *Foo = Function::Create(FunctionType::get(Builder.getVoidTy(), false),
+                                   GlobalValue::ExternalLinkage, "foo", M);
+  BasicBlock *Entry = BasicBlock::Create(Context, "entry", Foo);
+  Builder.SetInsertPoint(Entry);
+  Builder.CreateRetVoid();
+
+  CallGraph CG(M);
+  CallGraphSCC SCC(CG, nullptr);
+  SCC.initialize(CG[Foo]);
+
+  std::string Captured;
+  raw_string_ostream OS(Captured);
+  const std::string Banner = "*** TestPrintCallGraphBanner ***";
+
+  DummyCGSCCPass Helper;
+  std::unique_ptr<Pass> Printer(Helper.createPrinterPass(OS, Banner));
+
+  static_cast<CallGraphSCCPass *>(Printer.get())->runOnSCC(SCC);
+
+  ASSERT_GT(Captured.size(), Banner.size()) << Captured;
+  // Include one byte past the banner to verify it is terminated by '\n'.
+  EXPECT_EQ(Captured.substr(0, Banner.size() + 1), Banner + "\n");
+}
 }



More information about the llvm-commits mailing list