[llvm] [NFC][Support] Eliminate ', ' at end of MemoryEffects print (PR #106545)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 05:25:34 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/106545
>From 179395d988d3c89bf1701b1f8c43b9599c0542a6 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Thu, 29 Aug 2024 05:09:58 -0700
Subject: [PATCH] [NFC][Support] Eliminate ',' at end of MemoryEffects print
- Eliminate comma at end of a MemoryEffects print.
- Added basic unit test to validate that.
---
llvm/lib/Support/ModRef.cpp | 7 ++++---
llvm/unittests/Support/CMakeLists.txt | 1 +
llvm/unittests/Support/ModRefTest.cpp | 28 +++++++++++++++++++++++++++
3 files changed, 33 insertions(+), 3 deletions(-)
create mode 100644 llvm/unittests/Support/ModRefTest.cpp
diff --git a/llvm/lib/Support/ModRef.cpp b/llvm/lib/Support/ModRef.cpp
index c5978296e97f0c..b57ea30b93832f 100644
--- a/llvm/lib/Support/ModRef.cpp
+++ b/llvm/lib/Support/ModRef.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ModRef.h"
+#include "llvm/ADT/STLExtras.h"
using namespace llvm;
@@ -33,7 +34,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, ModRefInfo MR) {
}
raw_ostream &llvm::operator<<(raw_ostream &OS, MemoryEffects ME) {
- for (IRMemLocation Loc : MemoryEffects::locations()) {
+ interleaveComma(MemoryEffects::locations(), OS, [&](IRMemLocation Loc) {
switch (Loc) {
case IRMemLocation::ArgMem:
OS << "ArgMem: ";
@@ -45,7 +46,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, MemoryEffects ME) {
OS << "Other: ";
break;
}
- OS << ME.getModRef(Loc) << ", ";
- }
+ OS << ME.getModRef(Loc);
+ });
return OS;
}
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index db47a170e814a6..d64f89847aa8e7 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -61,6 +61,7 @@ add_llvm_unittest(SupportTests
MemoryBufferRefTest.cpp
MemoryBufferTest.cpp
MemoryTest.cpp
+ ModRefTest.cpp
NativeFormatTests.cpp
OptimizedStructLayoutTest.cpp
ParallelTest.cpp
diff --git a/llvm/unittests/Support/ModRefTest.cpp b/llvm/unittests/Support/ModRefTest.cpp
new file mode 100644
index 00000000000000..5ebb5f6a41a586
--- /dev/null
+++ b/llvm/unittests/Support/ModRefTest.cpp
@@ -0,0 +1,28 @@
+//===- llvm/unittest/Support/ModRefTest.cpp - ModRef tests ----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/ModRef.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+#include <string>
+
+using namespace llvm;
+
+namespace {
+
+// Verify that printing a MemoryEffects does not end with a ,.
+TEST(ModRefTest, PrintMemoryEffects) {
+ std::string S;
+ raw_string_ostream OS(S);
+ OS << MemoryEffects::none();
+ OS.flush();
+ EXPECT_EQ(S, "ArgMem: NoModRef, InaccessibleMem: NoModRef, Other: NoModRef");
+}
+
+} // namespace
More information about the llvm-commits
mailing list