Skip to content

Commit

Permalink
[NFC][Support] Eliminate ',' at end of MemoryEffects print (#106545)
Browse files Browse the repository at this point in the history
- Eliminate comma at end of a MemoryEffects print.
- Added basic unit test to validate that.
  • Loading branch information
jurahul authored Aug 29, 2024
1 parent c08c6a7 commit 115b876
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 4 additions & 3 deletions llvm/lib/Support/ModRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/Support/ModRef.h"
#include "llvm/ADT/STLExtras.h"

using namespace llvm;

Expand All @@ -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: ";
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions llvm/unittests/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_llvm_unittest(SupportTests
MemoryBufferRefTest.cpp
MemoryBufferTest.cpp
MemoryTest.cpp
ModRefTest.cpp
NativeFormatTests.cpp
OptimizedStructLayoutTest.cpp
ParallelTest.cpp
Expand Down
28 changes: 28 additions & 0 deletions llvm/unittests/Support/ModRefTest.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 115b876

Please sign in to comment.