Skip to content

Commit 115b876

Browse files
authored
[NFC][Support] Eliminate ',' at end of MemoryEffects print (#106545)
- Eliminate comma at end of a MemoryEffects print. - Added basic unit test to validate that.
1 parent c08c6a7 commit 115b876

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

llvm/lib/Support/ModRef.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "llvm/Support/ModRef.h"
14+
#include "llvm/ADT/STLExtras.h"
1415

1516
using namespace llvm;
1617

@@ -33,7 +34,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, ModRefInfo MR) {
3334
}
3435

3536
raw_ostream &llvm::operator<<(raw_ostream &OS, MemoryEffects ME) {
36-
for (IRMemLocation Loc : MemoryEffects::locations()) {
37+
interleaveComma(MemoryEffects::locations(), OS, [&](IRMemLocation Loc) {
3738
switch (Loc) {
3839
case IRMemLocation::ArgMem:
3940
OS << "ArgMem: ";
@@ -45,7 +46,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, MemoryEffects ME) {
4546
OS << "Other: ";
4647
break;
4748
}
48-
OS << ME.getModRef(Loc) << ", ";
49-
}
49+
OS << ME.getModRef(Loc);
50+
});
5051
return OS;
5152
}

llvm/unittests/Support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ add_llvm_unittest(SupportTests
6161
MemoryBufferRefTest.cpp
6262
MemoryBufferTest.cpp
6363
MemoryTest.cpp
64+
ModRefTest.cpp
6465
NativeFormatTests.cpp
6566
OptimizedStructLayoutTest.cpp
6667
ParallelTest.cpp

llvm/unittests/Support/ModRefTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- llvm/unittest/Support/ModRefTest.cpp - ModRef tests ----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/Support/ModRef.h"
10+
#include "llvm/ADT/SmallString.h"
11+
#include "llvm/Support/raw_ostream.h"
12+
#include "gtest/gtest.h"
13+
#include <string>
14+
15+
using namespace llvm;
16+
17+
namespace {
18+
19+
// Verify that printing a MemoryEffects does not end with a ,.
20+
TEST(ModRefTest, PrintMemoryEffects) {
21+
std::string S;
22+
raw_string_ostream OS(S);
23+
OS << MemoryEffects::none();
24+
OS.flush();
25+
EXPECT_EQ(S, "ArgMem: NoModRef, InaccessibleMem: NoModRef, Other: NoModRef");
26+
}
27+
28+
} // namespace

0 commit comments

Comments
 (0)