Skip to content

Commit c2bda5a

Browse files
committed
Check if prefix dir exists
1 parent cbfbd1b commit c2bda5a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

mlir/lib/Target/SPIRV/TranslateRegistration.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include "mlir/Target/SPIRV/Serialization.h"
2222
#include "mlir/Tools/mlir-translate/Translation.h"
2323
#include "llvm/ADT/StringRef.h"
24+
#include "llvm/Support/FileSystem.h"
2425
#include "llvm/Support/MemoryBuffer.h"
26+
#include "llvm/Support/Path.h"
2527
#include "llvm/Support/SourceMgr.h"
2628
#include "llvm/Support/ToolOutputFile.h"
2729

@@ -94,6 +96,17 @@ serializeModule(spirv::ModuleOp module, raw_ostream &output,
9496
output.write(reinterpret_cast<char *>(binary.data()), sizeInBytes);
9597

9698
if (options.saveModuleForValidation) {
99+
size_t dirSeparator =
100+
options.validationFilePrefix.find(llvm::sys::path::get_separator());
101+
// If file prefix includes directory check if that directory exists.
102+
if (dirSeparator != std::string::npos) {
103+
llvm::StringRef parentDir =
104+
llvm::sys::path::parent_path(options.validationFilePrefix);
105+
if (!llvm::sys::fs::is_directory(parentDir)) {
106+
llvm::errs() << "validation prefix directory does not exist\n";
107+
return failure();
108+
}
109+
}
97110
std::string errorMessage;
98111
std::string filename =
99112
options.validationFilePrefix + std::to_string(validationFileCounter++);

0 commit comments

Comments
 (0)