r240228 - ASTReader: Copy input file offset data to avoid unaligned accesses

David Majnemer david.majnemer at gmail.com
Sat Jun 20 17:08:15 PDT 2015


On Sat, Jun 20, 2015 at 5:01 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> Can we fix the users of this pointer instead of eagerly making a copy of
> the data?
>
What if we made it a pointer to a `unaligned_int64_t` ?



> 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
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D240228-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=kwYaPbS8NymK3f4XcSSPr5rBO1qeeQW2OEGEKsM-li8&s=koDwMVglgVCexLBKJTYHBAIUdecCmplqByqsswIwgoA&e=>
>> 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
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Serialization_Module.h-3Frev-3D240228-26r1-3D240227-26r2-3D240228-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=kwYaPbS8NymK3f4XcSSPr5rBO1qeeQW2OEGEKsM-li8&s=kMj8_X2N1MPqBzUHrVblxdIvIopnoGjPlqHFTtUJRYE&e=>
>>
>> ==============================================================================
>> --- 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
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Serialization_ASTReader.cpp-3Frev-3D240228-26r1-3D240227-26r2-3D240228-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=kwYaPbS8NymK3f4XcSSPr5rBO1qeeQW2OEGEKsM-li8&s=tYyGueRSfeVqYs8IooPMDV7_HNeh_uYnKyH87aCm5rI&e=>
>>
>> ==============================================================================
>> --- 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
>>
>
> _______________________________________________
> 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/c5097a55/attachment.html>


More information about the cfe-commits mailing list