[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Mon Jan 8 14:30:52 PST 2024


================
@@ -107,7 +107,15 @@ DecodedThread::CreateNewTraceItem(lldb::TraceItemKind kind) {
     (*m_last_tsc)->second.items_count++;
   if (m_last_nanoseconds)
     (*m_last_nanoseconds)->second.items_count++;
-  return m_item_data.back();
+
+  TraceItemStorage &data = m_item_data.back();
+
+  // If creating an error item, then properly initialize TraceItemStorage's
+  // non-trivially-constructible union member `error`.
+  if (kind == lldb::eTraceItemKindError)
+    new (&data.error) std::string();
----------------
walter-erquinigo wrote:

I see. Then I'm fine with `new (&data.error) std::string();`

But, if you want to make a more complex change that will also be very clean, you could use `std::variant` instead of `union` for `TraceItemStorage`. `std::variant` handles constructors and destructors nicely. Then we could also get rid of `m_item_kinds`. 

I'm fine with either option.

https://github.com/llvm/llvm-project/pull/77252


More information about the lldb-commits mailing list