From: Dean Michael Berris Date: Fri, 31 Aug 2018 10:03:52 +0000 (+0000) Subject: [XRay] Attempt to fix failure on Windows X-Git-Tag: llvmorg-8.0.0-rc1~9667 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a07a41cbb4c48db19c49bda99479cfdec7d3a0d;p=platform%2Fupstream%2Fllvm.git [XRay] Attempt to fix failure on Windows Original version of the code relied on implementation-defined order of bitfields. Follow-up on D51210. llvm-svn: 341194 --- diff --git a/llvm/lib/XRay/FDRTraceWriter.cpp b/llvm/lib/XRay/FDRTraceWriter.cpp index 0148c6b..b9b71eb 100644 --- a/llvm/lib/XRay/FDRTraceWriter.cpp +++ b/llvm/lib/XRay/FDRTraceWriter.cpp @@ -21,9 +21,8 @@ namespace { struct alignas(32) FileHeader { uint16_t Version; uint16_t Type; - bool ConstantTSC : 1; - bool NonstopTSC : 1; - alignas(8) uint64_t CycleFrequency; + uint32_t BitField; + uint64_t CycleFrequency; char FreeForm[16]; }; @@ -65,7 +64,7 @@ template struct IndexedMemcpy { }; template -Error writeMetadata(raw_ostream &OS, Values&&... Ds) { +Error writeMetadata(raw_ostream &OS, Values &&... Ds) { MetadataBlob B; B.Type = 1; B.RecordKind = Kind; @@ -85,8 +84,7 @@ FDRTraceWriter::FDRTraceWriter(raw_ostream &O, const XRayFileHeader &H) FileHeader Raw; Raw.Version = H.Version; Raw.Type = H.Type; - Raw.ConstantTSC = H.ConstantTSC; - Raw.NonstopTSC = H.NonstopTSC; + Raw.BitField = (H.ConstantTSC ? 0x01 : 0x0) | (H.NonstopTSC ? 0x02 : 0x0); Raw.CycleFrequency = H.CycleFrequency; memcpy(&Raw.FreeForm, H.FreeFormData, 16); OS.write(reinterpret_cast(&Raw), sizeof(XRayFileHeader)); diff --git a/llvm/unittests/XRay/FDRTraceWriterTest.cpp b/llvm/unittests/XRay/FDRTraceWriterTest.cpp index 9d7da50..97a0119 100644 --- a/llvm/unittests/XRay/FDRTraceWriterTest.cpp +++ b/llvm/unittests/XRay/FDRTraceWriterTest.cpp @@ -135,6 +135,11 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) { std::memcpy(H.FreeFormData, reinterpret_cast(&BufferSize), sizeof(BufferSize)); FDRTraceWriter Writer(OS, H); + OS.flush(); + + // Ensure that at this point the Data buffer has the file header serialized + // size. + ASSERT_THAT(Data.size(), Eq(32u)); auto L = LogBuilder() .add(1) .add(1, 1) @@ -150,6 +155,10 @@ TEST(FDRTraceWriterTest, WriteToStringBufferVersion1) { OS.write_zeros(4016); OS.flush(); + // For version 1 of the log, we need the whole buffer to be the size of the + // file header plus 32. + ASSERT_THAT(Data.size(), Eq(BufferSize + 32)); + // Then from here we load the Trace file. DataExtractor DE(Data, true, 8); auto TraceOrErr = loadTrace(DE, true);