Previously, I attributed the potential problems here too heavily to LLVM. Currently, I have noticed another reason why this usage might still be broken even without considering LLVM’s aliasing rules—padding.
Zig may fill the padding of a struct to record type safety information. Although the current implementation may not do this, I think we have to prepare for the worst case. E.g., when we dereference a struct in any way to get the address of its fields(var left: *T = self.mock_head(); var right_opt: ?*T = @field(left, right_field_name);), the padding could potentially be written with information.
This means that when we use a mock head that doesn’t actually exist, it could cause Zig to fill the padding part of the struct, resulting in unexpected memory corruption. Therefore, even without using the LLVM backend, I think the mock head is not valid.