summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-11-09 07:16:45 +0000
committerDean Michael Berris <dberris@google.com>2018-11-09 07:16:45 +0000
commitead47aab7827c9720f2f85291a86164f982eeb59 (patch)
tree9c30f0b8f516118d3a43d0fd67e41d5b7d52ca1c
parente39a89fbfb2902d8557665f75f0d1acacbc86d26 (diff)
downloadbcm5719-llvm-ead47aab7827c9720f2f85291a86164f982eeb59.tar.gz
bcm5719-llvm-ead47aab7827c9720f2f85291a86164f982eeb59.zip
[XRay] Add a static assertion on size of metadata payload (NFC)
This change adds a static check to ensure that all data metadata record payloads don't go past the available buffers in Metadata records. llvm-svn: 346476
-rw-r--r--compiler-rt/lib/xray/xray_fdr_log_writer.h19
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);
OpenPOWER on IntegriCloud