In future I want to extend RegisterInfo and that will likely be non trivial
types like string and vector. RegisterInfo gets stored in Context, so Context
must be changed to a discriminated enum that properly calls destructors.
(which would be std::variant but although llvm is using -std=c++17 I don't
think we can expect c++17 library features just yet)
As so much existing code does this:
Context ctx;
// Lots of code that interacts with ctx...
ctx.Set<...>
I wasn't able to switch to factory functions for the Set<...> methods without a lot
more changes. Instead I've made the default constructor construct to the NoArgs type
and then Set<...> will change the type later.
Whenever you call a Set<...> it will destroy whatever is currently in the union
before setting the new data. Potentially non trivial types like RegisterInfos here are
placement newed because otherwise operator= would try to destroy the existing data
which is in fact uninitialised memory as far as we're concerned.
For the destructor we switch on the current info_type to know what to destruct.
(info_type that was made private in a previous change, so we know we have control of it)
Some places in lldb were using memset to initalise RegisterInfos. I tracked these
down with GCC's -Wclass-memaccess.
https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#index-Wclass-memaccess
To replace these I've added sensible default values for each member in RegisterInfo
and filled kinds with LLDB_INVALID_REGNUM in the default constructor.
Depends on D134039
clang-format not found in user’s local PATH; not linting file.