[llvm] r341194 - [XRay] Attempt to fix failure on Windows

Dean Michael Berris via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 31 03:03:52 PDT 2018


Author: dberris
Date: Fri Aug 31 03:03:52 2018
New Revision: 341194

URL: http://llvm.org/viewvc/llvm-project?rev=341194&view=rev
Log:
[XRay] Attempt to fix failure on Windows

Original version of the code relied on implementation-defined order of bitfields.

Follow-up on D51210.

Modified:
    llvm/trunk/lib/XRay/FDRTraceWriter.cpp
    llvm/trunk/unittests/XRay/FDRTraceWriterTest.cpp

Modified: llvm/trunk/lib/XRay/FDRTraceWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/FDRTraceWriter.cpp?rev=341194&r1=341193&r2=341194&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/FDRTraceWriter.cpp (original)
+++ llvm/trunk/lib/XRay/FDRTraceWriter.cpp Fri Aug 31 03:03:52 2018
@@ -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 <size_t Index> struct IndexedMe
 };
 
 template <uint8_t Kind, class... Values>
-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_ostre
   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<const char *>(&Raw), sizeof(XRayFileHeader));

Modified: llvm/trunk/unittests/XRay/FDRTraceWriterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/XRay/FDRTraceWriterTest.cpp?rev=341194&r1=341193&r2=341194&view=diff
==============================================================================
--- llvm/trunk/unittests/XRay/FDRTraceWriterTest.cpp (original)
+++ llvm/trunk/unittests/XRay/FDRTraceWriterTest.cpp Fri Aug 31 03:03:52 2018
@@ -135,6 +135,11 @@ TEST(FDRTraceWriterTest, WriteToStringBu
   std::memcpy(H.FreeFormData, reinterpret_cast<const char *>(&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<NewBufferRecord>(1)
                .add<WallclockRecord>(1, 1)
@@ -150,6 +155,10 @@ TEST(FDRTraceWriterTest, WriteToStringBu
   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);




More information about the llvm-commits mailing list