<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 12, 2014 at 2:22 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: bogner<br>
Date: Fri Sep 12 16:22:55 2014<br>
New Revision: 217708<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=217708&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=217708&view=rev</a><br>
Log:<br>
llvm-profdata: Avoid undefined behaviour when reading raw profiles<br>
<br>
The raw profiles that are generated in compiler-rt always add padding<br>
so that each profile is aligned, so we can simply treat files that<br>
don't have this property as malformed.<br></blockquote><div><br></div><div>Any chance of changing this to not rely on UB (this code looks like it's violating C++ aliasing rules pretty consistently) and instead using memcpy?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Caught by Alexey's new ubsan bot. Thanks!<br>
<br>
Modified:<br>
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp<br>
    llvm/trunk/test/tools/llvm-profdata/raw-two-profiles.test<br>
<br>
Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=217708&r1=217707&r2=217708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=217708&r1=217707&r2=217708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Fri Sep 12 16:22:55 2014<br>
@@ -190,6 +190,9 @@ RawInstrProfReader<IntPtrT>::readNextHea<br>
   // garbage at the end of the file.<br>
   if (CurrentPos + sizeof(RawHeader) > End)<br>
     return instrprof_error::malformed;<br>
+  // The writer ensures each profile is padded to start at an aligned address.<br>
+  if (reinterpret_cast<size_t>(CurrentPos) % alignOf<uint64_t>())<br>
+    return instrprof_error::malformed;<br>
   // The magic should have the same byte order as in the previous header.<br>
   uint64_t Magic = *reinterpret_cast<const uint64_t *>(CurrentPos);<br>
   if (Magic != swap(getRawMagic<IntPtrT>()))<br>
<br>
Modified: llvm/trunk/test/tools/llvm-profdata/raw-two-profiles.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/raw-two-profiles.test?rev=217708&r1=217707&r2=217708&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/raw-two-profiles.test?rev=217708&r1=217707&r2=217708&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-profdata/raw-two-profiles.test (original)<br>
+++ llvm/trunk/test/tools/llvm-profdata/raw-two-profiles.test Fri Sep 12 16:22:55 2014<br>
@@ -39,11 +39,9 @@ RUN: printf '\0\0\0\0\0' >> %t-foo-padde<br>
 RUN: cat %t-bar.profraw > %t-bar-padded.profraw<br>
 RUN: printf '\0\0\0\0\0' >> %t-bar-padded.profraw<br>
<br>
-RUN: cat %t-foo.profraw %t-bar.profraw > %t-nopad.profraw<br>
 RUN: cat %t-foo-padded.profraw %t-bar.profraw > %t-pad-between.profraw<br>
 RUN: cat %t-foo-padded.profraw %t-bar-padded.profraw > %t-pad.profraw<br>
<br>
-RUN: llvm-profdata show %t-nopad.profraw -all-functions -counts | FileCheck %s<br>
 RUN: llvm-profdata show %t-pad-between.profraw -all-functions -counts | FileCheck %s<br>
 RUN: llvm-profdata show %t-pad.profraw -all-functions -counts | FileCheck %s<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>