diff options
-rw-r--r-- | compiler-rt/lib/xray/xray_fdr_log_writer.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler-rt/lib/xray/xray_fdr_log_writer.h b/compiler-rt/lib/xray/xray_fdr_log_writer.h index c18ff7bbf0b..9ab44fcb001 100644 --- a/compiler-rt/lib/xray/xray_fdr_log_writer.h +++ b/compiler-rt/lib/xray/xray_fdr_log_writer.h @@ -46,8 +46,27 @@ template <size_t Index> struct SerializerImpl { using Serializer = SerializerImpl<0>; +template <class Tuple, size_t Index> struct AggregateSizesImpl { + static constexpr size_t value = + sizeof(typename std::tuple_element<Index, Tuple>::type) + + AggregateSizesImpl<Tuple, Index - 1>::value; +}; + +template <class Tuple> struct AggregateSizesImpl<Tuple, 0> { + static constexpr size_t value = + sizeof(typename std::tuple_element<0, Tuple>::type); +}; + +template <class Tuple> struct AggregateSizes { + static constexpr size_t value = + AggregateSizesImpl<Tuple, std::tuple_size<Tuple>::value - 1>::value; +}; + template <MetadataRecord::RecordKinds Kind, class... DataTypes> MetadataRecord createMetadataRecord(DataTypes &&... Ds) { + static_assert(AggregateSizes<std::tuple<DataTypes...>>::value <= + sizeof(MetadataRecord) - 1, + "Metadata payload longer than metadata buffer!"); MetadataRecord R; R.Type = 1; R.RecordKind = static_cast<uint8_t>(Kind); |