forked from OSchip/llvm-project
ASTReader: Copy input file offset data to avoid unaligned accesses
We interpret Blob as an array of uint64_t here, but there's no reason to think that it has suitable alignment. Instead, read the data in in an alignment-safe way and store it in a std::vector. This fixes 225 test failures when clang is built with ubsan. llvm-svn: 240228
This commit is contained in:
parent
db8ef097be
commit
2172c3a3c8
|
@ -206,7 +206,7 @@ public:
|
|||
llvm::BitstreamCursor InputFilesCursor;
|
||||
|
||||
/// \brief Offsets for all of the input file entries in the AST file.
|
||||
const uint64_t *InputFileOffsets;
|
||||
std::vector<uint64_t> InputFileOffsets;
|
||||
|
||||
/// \brief The input files that have been loaded from this AST file.
|
||||
std::vector<InputFile> InputFilesLoaded;
|
||||
|
|
|
@ -2304,13 +2304,21 @@ ASTReader::ReadControlBlock(ModuleFile &F,
|
|||
return Result;
|
||||
break;
|
||||
|
||||
case INPUT_FILE_OFFSETS:
|
||||
case INPUT_FILE_OFFSETS: {
|
||||
NumInputs = Record[0];
|
||||
NumUserInputs = Record[1];
|
||||
F.InputFileOffsets = (const uint64_t *)Blob.data();
|
||||
F.InputFileOffsets.clear();
|
||||
F.InputFileOffsets.reserve(NumInputs);
|
||||
using namespace llvm::support;
|
||||
const char *Buf = Blob.data();
|
||||
for (unsigned int I = 0; I < NumInputs; ++I)
|
||||
F.InputFileOffsets.push_back(
|
||||
endian::readNext<uint64_t, native, unaligned>(Buf));
|
||||
|
||||
F.InputFilesLoaded.resize(NumInputs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue