[flang] Replace access through union with reinterpret_cast.

This avoids undefined behaviour.

Original-commit: flang-compiler/f18@e289bbfa83
Reviewed-on: https://github.com/flang-compiler/f18/pull/767
Tree-same-pre-rewrite: false
This commit is contained in:
David Truby 2019-09-30 12:41:34 +01:00
parent 5e86f88937
commit c579118ce6
2 changed files with 3 additions and 13 deletions

View File

@ -129,23 +129,13 @@ template<typename TR, typename... ArgInfo> struct CallableHostWrapper {
template<typename TR, typename... TA>
inline GenericFunctionPointer ToGenericFunctionPointer(
FuncPointer<TR, TA...> f) {
union {
GenericFunctionPointer gp;
FuncPointer<TR, TA...> fp;
} u;
u.fp = f;
return u.gp;
return reinterpret_cast<GenericFunctionPointer>(f);
}
template<typename TR, typename... TA>
inline FuncPointer<TR, TA...> FromGenericFunctionPointer(
GenericFunctionPointer g) {
union {
GenericFunctionPointer gp;
FuncPointer<TR, TA...> fp;
} u;
u.gp = g;
return u.fp;
return reinterpret_cast<FuncPointer<TR, TA...>>(g);
}
template<typename TR, typename... ArgInfo>

View File

@ -35,7 +35,7 @@ class FoldingContext;
using TypeCode = unsigned char;
template<typename TR, typename... TA> using FuncPointer = TR (*)(TA...);
using GenericFunctionPointer = FuncPointer<void *>;
using GenericFunctionPointer = void (*) (void);
enum class PassBy { Ref, Val };
template<typename TA, PassBy Pass = PassBy::Ref> struct ArgumentInfo {