Skip to content

Commit 3d016ad

Browse files
authored
Merge pull request #6255 from akyrtzi/pr/stable2/fix-optional-assertion
[CAS/LazyMappedFileRegion] Fix assertion hit while using `std::optional`
2 parents b21a4da + 71109e7 commit 3d016ad

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

llvm/lib/CAS/LazyMappedFileRegion.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,29 +243,30 @@ Expected<LazyMappedFileRegion> LazyMappedFileRegion::create(
243243
sys::fs::file_t File = sys::fs::convertFDToNativeFile(FD);
244244

245245
struct FileLockRAII {
246-
LazyMappedFileRegion &LMFR;
246+
std::string Path;
247+
int FD;
247248
bool IsLocked = false;
248249

249250
enum LockKind { Shared, Exclusive };
250251

251-
FileLockRAII(LazyMappedFileRegion &LMFR) : LMFR(LMFR) {}
252+
FileLockRAII(LazyMappedFileRegion &LMFR) : Path(LMFR.Path), FD(*LMFR.FD) {}
252253
~FileLockRAII() { consumeError(unlock()); }
253254

254255
Error lock(LockKind LK) {
255256
if (IsLocked)
256257
return createStringError(inconvertibleErrorCode(),
257-
LMFR.Path + " already locked");
258-
if (std::error_code EC = sys::fs::lockFile(*LMFR.FD, LK == Exclusive))
259-
return createFileError(LMFR.Path, EC);
258+
Path + " already locked");
259+
if (std::error_code EC = sys::fs::lockFile(FD, LK == Exclusive))
260+
return createFileError(Path, EC);
260261
IsLocked = true;
261262
return Error::success();
262263
}
263264

264265
Error unlock() {
265266
if (IsLocked) {
266267
IsLocked = false;
267-
if (std::error_code EC = sys::fs::unlockFile(*LMFR.FD))
268-
return createFileError(LMFR.Path, EC);
268+
if (std::error_code EC = sys::fs::unlockFile(FD))
269+
return createFileError(Path, EC);
269270
}
270271
return Error::success();
271272
}

0 commit comments

Comments
 (0)