[LLDB] Check that RegisterInfo and ContextInfo are trivial
authorDavid Spickett <david.spickett@linaro.org>
Mon, 24 Oct 2022 08:54:33 +0000 (08:54 +0000)
committerDavid Spickett <david.spickett@linaro.org>
Mon, 24 Oct 2022 10:16:29 +0000 (10:16 +0000)
RegisterInfo is often initialised with a memcpy, and ContextInfo
does not run destructors for anything within it.

This was discussed in https://reviews.llvm.org/D134041.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D136584

lldb/include/lldb/Core/EmulateInstruction.h
lldb/include/lldb/lldb-private-types.h

index 65b7982c36a0bd3ffb2b52e4e3c59f000f04da0c..64633e9cf29be41b4c6e82d23a732434d86a48fc 100644 (file)
@@ -189,7 +189,7 @@ public:
 
   public:
     enum InfoType GetInfoType() const { return info_type; }
-    union {
+    union ContextInfo {
       struct RegisterPlusOffset {
         RegisterInfo reg;      // base register
         int64_t signed_offset; // signed offset added to base register
@@ -241,6 +241,8 @@ public:
 
       uint32_t isa;
     } info;
+    static_assert(std::is_trivial<ContextInfo>::value,
+                  "ContextInfo must be trivial.");
 
     Context() = default;
 
index 1b0d263e2073b09faed54dd47d31d25fd57ea141..edc1c78985bddfd2a5ed287ef322172e96c94d21 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "llvm/ADT/ArrayRef.h"
 
+#include <type_traits>
+
 namespace llvm {
 namespace sys {
 class DynamicLibrary;
@@ -70,6 +72,8 @@ struct RegisterInfo {
                                           byte_size);
   }
 };
+static_assert(std::is_trivial<RegisterInfo>::value,
+              "RegisterInfo must be trivial.");
 
 /// Registers are grouped into register sets
 struct RegisterSet {