r240228 - ASTReader: Copy input file offset data to avoid unaligned accesses
Justin Bogner
mail at justinbogner.com
Sat Jun 20 15:31:05 PDT 2015
Author: bogner
Date: Sat Jun 20 17:31:04 2015
New Revision: 240228
URL: http://llvm.org/viewvc/llvm-project?rev=240228&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/Serialization/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/Module.h?rev=240228&r1=240227&r2=240228&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/Module.h (original)
+++ cfe/trunk/include/clang/Serialization/Module.h Sat Jun 20 17:31:04 2015
@@ -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;
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=240228&r1=240227&r2=240228&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat Jun 20 17:31:04 2015
@@ -2304,13 +2304,21 @@ ASTReader::ReadControlBlock(ModuleFile &
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;
}
+ }
}
}
More information about the cfe-commits
mailing list