Fix more undefined behaviours identified by clang
Change UnionType to use unordered_set to store union entries.