This is an archive of the discontinued LLVM Phabricator instance.

Fix UB in MCJIT test cases that relied on union type punning
ClosedPublic

Authored by dblaikie on Aug 5 2015, 2:19 PM.

Diff Detail

Event Timeline

dblaikie updated this revision to Diff 31394.Aug 5 2015, 2:19 PM
dblaikie retitled this revision from to Fix UB in MCJIT test cases that relied on union type punning.
dblaikie added reviewers: lhames, aaron.ballman.
dblaikie added a subscriber: llvm-commits.
aaron.ballman edited edge metadata.Aug 5 2015, 2:24 PM

Thank you for taking care of this! Generally, LGTM, but I do wonder if it might make sense to make something like (totally untested):

template <typename InTy, typename OutTy>
static inline OutTy safe_cast_fn_ptr(InTy fn) {

return reinterpret_cast<OutTy>(reinterpret_cast<uintptr_t>(fn));

}

And use it in place of the extra type casting, since there's a fair amount of it in this test file?

~Aaron

Yeah, I'd be OK with that, for sure. (probably add some checks to ensure
the source/dest types are pointers, probably, somehow, maybe)

hans added a subscriber: hans.Aug 6 2015, 9:10 AM
lhames accepted this revision.Aug 11 2015, 11:15 AM
lhames edited edge metadata.

Apologies for the late reply - I've out on vacation.

This looks great. Thanks for the fix Dave!

This revision is now accepted and ready to land.Aug 11 2015, 11:15 AM
This revision was automatically updated to reflect the committed changes.