Original version of the code relied on implementation-defined order of bitfields.
Follow-up on D51210.
llvm-svn: 341194
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];
};
};
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;
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));
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)
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);