Skip to content

Commit 066fe47

Browse files
committed
address copilot
1 parent e4292d1 commit 066fe47

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

mlir/include/mlir/IR/Remarks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class RemarkBase : public llvm::DiagnosticInfo {
8282

8383
virtual bool isEnabled() const = 0;
8484
Location getLocation() const { return loc; }
85-
llvm::remarks::RemarkLocation getRemarkLocation() const;
8685
/// Diagnostic -> Remark
8786
llvm::remarks::Remark generateRemark() const;
8887

mlir/lib/IR/Remarks.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,19 @@ llvm::remarks::Type RemarkBase::getRemarkType() const {
103103
llvm_unreachable("Unknown remark kind");
104104
}
105105

106-
llvm::remarks::RemarkLocation RemarkBase::getRemarkLocation() const {
107-
if (auto flc = dyn_cast<FileLineColLoc>(getLocation())) {
108-
auto *buf = new std::string("./" + flc.getFilename().str());
109-
return {*buf, flc.getLine(), flc.getColumn()};
110-
}
111-
return {"<unknown file>", 0, 0};
112-
}
113-
114106
llvm::remarks::Remark RemarkBase::generateRemark() const {
107+
auto locLambda = [&]() -> llvm::remarks::RemarkLocation {
108+
if (auto flc = dyn_cast<FileLineColLoc>(getLocation()))
109+
return {flc.getFilename(), flc.getLine(), flc.getColumn()};
110+
return {"<unknown file>", 0, 0};
111+
};
112+
115113
llvm::remarks::Remark r; // The result.
116114
r.RemarkType = getRemarkType();
117115
r.PassName = getPassName();
118116
r.RemarkName = getRemarkName();
119117
r.FunctionName = getFunction();
120-
r.Loc = getRemarkLocation();
118+
r.Loc = locLambda();
121119
for (const RemarkBase::RemarkKeyValue &arg : getArgs()) {
122120
r.Args.emplace_back();
123121
r.Args.back().Key = arg.key;

mlir/unittests/IR/RemarkTest.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ TEST(Remark, TestOutputOptimizationRemark) {
3333
std::string myPassname1("myPass1");
3434
std::string myPassname2("myPass2");
3535
std::string funcName("myFunc");
36-
std::string yamlFile = "/tmp/remarks.yaml";
37-
36+
SmallString<64> tmpPathStorage;
37+
sys::fs::createUniquePath("remarks-%%%%%%.yaml", tmpPathStorage,
38+
/*MakeAbsolute=*/true);
39+
std::string yamlFile =
40+
std::string(tmpPathStorage.data(), tmpPathStorage.size());
41+
ASSERT_FALSE(yamlFile.empty());
3842
Location loc = UnknownLoc::get(context);
3943

4044
// Setup the remark engine
@@ -77,14 +81,17 @@ TEST(Remark, TestOutputOptimizationRemark) {
7781

7882
TEST(Remark, TestNoOutputOptimizationRemark) {
7983
const auto *pass1Msg = "My message";
80-
8184
auto *context = new MLIRContext();
8285

8386
std::string categoryFailName("myImportantCategory");
8487
std::string myPassname1("myPass1");
8588
std::string funcName("myFunc");
86-
std::string yamlFile = "/tmp/remarks.yaml";
87-
89+
SmallString<64> tmpPathStorage;
90+
sys::fs::createUniquePath("remarks-%%%%%%.yaml", tmpPathStorage,
91+
/*MakeAbsolute=*/true);
92+
std::string yamlFile =
93+
std::string(tmpPathStorage.data(), tmpPathStorage.size());
94+
ASSERT_FALSE(yamlFile.empty());
8895
std::error_code ec =
8996
llvm::sys::fs::remove(yamlFile, /*IgnoreNonExisting=*/true);
9097
if (ec) {

0 commit comments

Comments
 (0)