r240228 - ASTReader: Copy input file offset data to avoid unaligned accesses
Richard Smith
richard at metafoo.co.uk
Sat Jun 20 17:01:10 PDT 2015
Can we fix the users of this pointer instead of eagerly making a copy of
the data?
On 20 Jun 2015 3:38 pm, "Justin Bogner" <mail at justinbogner.com> wrote:
> 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;
> }
> + }
> }
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150620/1ec126b6/attachment.html>
More information about the cfe-commits
mailing list