r240247 - ASTReader: Treat InputFileOffsets as unaligned to avoid UB
Justin Bogner
mail at justinbogner.com
Sun Jun 21 13:32:40 PDT 2015
Author: bogner
Date: Sun Jun 21 15:32:40 2015
New Revision: 240247
URL: http://llvm.org/viewvc/llvm-project?rev=240247&view=rev
Log:
ASTReader: Treat InputFileOffsets as unaligned to avoid UB
This is a better approach to fixing the undefined behaviour I tried to
fix in r240228. This data doesn't necessarily have suitable alignment
for uint64_t, so use unaligned_uint64_t instead.
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=240247&r1=240246&r2=240247&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/Module.h (original)
+++ cfe/trunk/include/clang/Serialization/Module.h Sun Jun 21 15:32:40 2015
@@ -20,6 +20,7 @@
#include "clang/Serialization/ContinuousRangeMap.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Bitcode/BitstreamReader.h"
+#include "llvm/Support/Endian.h"
#include <memory>
#include <string>
@@ -206,7 +207,7 @@ public:
llvm::BitstreamCursor InputFilesCursor;
/// \brief Offsets for all of the input file entries in the AST file.
- const uint64_t *InputFileOffsets;
+ const llvm::support::unaligned_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=240247&r1=240246&r2=240247&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun Jun 21 15:32:40 2015
@@ -2307,7 +2307,8 @@ ASTReader::ReadControlBlock(ModuleFile &
case INPUT_FILE_OFFSETS:
NumInputs = Record[0];
NumUserInputs = Record[1];
- F.InputFileOffsets = (const uint64_t *)Blob.data();
+ F.InputFileOffsets =
+ (const llvm::support::unaligned_uint64_t *)Blob.data();
F.InputFilesLoaded.resize(NumInputs);
break;
}
More information about the cfe-commits
mailing list