[BOLT] Handle access errors while reading profile
When the user does not have permissions to access the profile, consume the error contained in Expected<> to avoid dumping stack to the user. Differential Revision: https://reviews.llvm.org/D139480
This commit is contained in:
parent
f6b1d88527
commit
0f915826cc
|
@ -327,15 +327,22 @@ bool DataAggregator::checkPerfDataMagic(StringRef FileName) {
|
|||
return true;
|
||||
|
||||
Expected<sys::fs::file_t> FD = sys::fs::openNativeFileForRead(FileName);
|
||||
if (!FD)
|
||||
if (!FD) {
|
||||
consumeError(FD.takeError());
|
||||
return false;
|
||||
}
|
||||
|
||||
char Buf[7] = {0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
auto Close = make_scope_exit([&] { sys::fs::closeFile(*FD); });
|
||||
Expected<size_t> BytesRead = sys::fs::readNativeFileSlice(
|
||||
*FD, makeMutableArrayRef(Buf, sizeof(Buf)), 0);
|
||||
if (!BytesRead || *BytesRead != 7)
|
||||
if (!BytesRead) {
|
||||
consumeError(BytesRead.takeError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*BytesRead != 7)
|
||||
return false;
|
||||
|
||||
if (strncmp(Buf, "PERFILE", 7) == 0)
|
||||
|
|
13
bolt/test/unreadable-profile.test
Normal file
13
bolt/test/unreadable-profile.test
Normal file
|
@ -0,0 +1,13 @@
|
|||
REQUIRES: system-linux
|
||||
|
||||
RUN: touch %t.profile && chmod 000 %t.profile
|
||||
RUN: %clang %S/Inputs/hello.c -o %t
|
||||
RUN: not llvm-bolt %t -o %t.bolt --data %t.profile 2>&1 \
|
||||
RUN: | FileCheck %s --check-prefix CHECK-NOPERM
|
||||
RUN: not llvm-bolt %t -o %t.bolt --data %t.fake.profile 2>&1 \
|
||||
RUN: | FileCheck %s --check-prefix CHECK-FAKE
|
||||
|
||||
## Check that llvm-bolt gracefully handles errors accessing profile data.
|
||||
|
||||
CHECK-NOPERM: Permission denied
|
||||
CHECK-FAKE: No such file or directory
|
Loading…
Reference in New Issue
Block a user