<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jun 20, 2015 at 5:01 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><p dir="ltr">Can we fix the users of this pointer instead of eagerly making a copy of the data?</p></blockquote><div>What if we made it a pointer to a `unaligned_int64_t` ?</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">
<div class="gmail_quote">On 20 Jun 2015 3:38 pm, "Justin Bogner" <<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: bogner<br>
Date: Sat Jun 20 17:31:04 2015<br>
New Revision: 240228<br>
<br>
URL: <a href="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=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=240228&view=rev</a><br>
Log:<br>
ASTReader: Copy input file offset data to avoid unaligned accesses<br>
<br>
We interpret Blob as an array of uint64_t here, but there's no reason<br>
to think that it has suitable alignment. Instead, read the data in in<br>
an alignment-safe way and store it in a std::vector.<br>
<br>
This fixes 225 test failures when clang is built with ubsan.<br>
<br>
Modified:<br>
cfe/trunk/include/clang/Serialization/Module.h<br>
cfe/trunk/lib/Serialization/ASTReader.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Serialization/Module.h<br>
URL: <a href="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=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/Module.h?rev=240228&r1=240227&r2=240228&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Serialization/Module.h (original)<br>
+++ cfe/trunk/include/clang/Serialization/Module.h Sat Jun 20 17:31:04 2015<br>
@@ -206,7 +206,7 @@ public:<br>
llvm::BitstreamCursor InputFilesCursor;<br>
<br>
/// \brief Offsets for all of the input file entries in the AST file.<br>
- const uint64_t *InputFileOffsets;<br>
+ std::vector<uint64_t> InputFileOffsets;<br>
<br>
/// \brief The input files that have been loaded from this AST file.<br>
std::vector<InputFile> InputFilesLoaded;<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp<br>
URL: <a href="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=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=240228&r1=240227&r2=240228&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sat Jun 20 17:31:04 2015<br>
@@ -2304,13 +2304,21 @@ ASTReader::ReadControlBlock(ModuleFile &<br>
return Result;<br>
break;<br>
<br>
- case INPUT_FILE_OFFSETS:<br>
+ case INPUT_FILE_OFFSETS: {<br>
NumInputs = Record[0];<br>
NumUserInputs = Record[1];<br>
- F.InputFileOffsets = (const uint64_t *)Blob.data();<br>
+ F.InputFileOffsets.clear();<br>
+ F.InputFileOffsets.reserve(NumInputs);<br>
+ using namespace llvm::support;<br>
+ const char *Buf = Blob.data();<br>
+ for (unsigned int I = 0; I < NumInputs; ++I)<br>
+ F.InputFileOffsets.push_back(<br>
+ endian::readNext<uint64_t, native, unaligned>(Buf));<br>
+<br>
F.InputFilesLoaded.resize(NumInputs);<br>
break;<br>
}<br>
+ }<br>
}<br>
}<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</div></div><br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div>