Fix Target.RealProperties potentially aliasing Target.DoubleProperties

In case the host real_t is double (e.g., for MSVC hosts).
This commit is contained in:
Martin 2017-06-10 04:23:32 +02:00
parent 45eacd0f32
commit 03d803419d
3 changed files with 36 additions and 27 deletions

View file

@ -56,7 +56,12 @@ struct Target
alias FloatProperties = FPTypeProperties!float; alias FloatProperties = FPTypeProperties!float;
alias DoubleProperties = FPTypeProperties!double; alias DoubleProperties = FPTypeProperties!double;
version(IN_LLVM) {
// host real_t may be double => make sure not to alias target's DoubleProperties
extern (C++) static __gshared FPTypeProperties!real_t RealProperties;
} else {
alias RealProperties = FPTypeProperties!real_t; alias RealProperties = FPTypeProperties!real_t;
}
version(IN_LLVM) version(IN_LLVM)
{ {

View file

@ -56,7 +56,11 @@ struct Target
typedef FPTypeProperties<float> FloatProperties; typedef FPTypeProperties<float> FloatProperties;
typedef FPTypeProperties<double> DoubleProperties; typedef FPTypeProperties<double> DoubleProperties;
#if IN_LLVM
static FPTypeProperties<real_t> RealProperties;
#else
typedef FPTypeProperties<real_t> RealProperties; typedef FPTypeProperties<real_t> RealProperties;
#endif
static void _init(); static void _init();
// Type sizes and support. // Type sizes and support.

View file

@ -56,39 +56,39 @@ void Target::_init() {
#endif #endif
if (targetRealSemantics == IEEEdouble) { if (targetRealSemantics == IEEEdouble) {
RealProperties::max = CTFloat::parse("0x1.fffffffffffffp+1023"); RealProperties.max = CTFloat::parse("0x1.fffffffffffffp+1023");
RealProperties::min_normal = CTFloat::parse("0x1p-1022"); RealProperties.min_normal = CTFloat::parse("0x1p-1022");
RealProperties::epsilon = CTFloat::parse("0x1p-52"); RealProperties.epsilon = CTFloat::parse("0x1p-52");
RealProperties::dig = 15; RealProperties.dig = 15;
RealProperties::mant_dig = 53; RealProperties.mant_dig = 53;
RealProperties::max_exp = 1024; RealProperties.max_exp = 1024;
RealProperties::min_exp = -1021; RealProperties.min_exp = -1021;
RealProperties::max_10_exp = 308; RealProperties.max_10_exp = 308;
RealProperties::min_10_exp = -307; RealProperties.min_10_exp = -307;
} else if (targetRealSemantics == x87DoubleExtended) { } else if (targetRealSemantics == x87DoubleExtended) {
RealProperties::max = CTFloat::parse("0x1.fffffffffffffffep+16383"); RealProperties.max = CTFloat::parse("0x1.fffffffffffffffep+16383");
RealProperties::min_normal = CTFloat::parse("0x1p-16382"); RealProperties.min_normal = CTFloat::parse("0x1p-16382");
RealProperties::epsilon = CTFloat::parse("0x1p-63"); RealProperties.epsilon = CTFloat::parse("0x1p-63");
RealProperties::dig = 18; RealProperties.dig = 18;
RealProperties::mant_dig = 64; RealProperties.mant_dig = 64;
RealProperties::max_exp = 16384; RealProperties.max_exp = 16384;
RealProperties::min_exp = -16381; RealProperties.min_exp = -16381;
RealProperties::max_10_exp = 4932; RealProperties.max_10_exp = 4932;
RealProperties::min_10_exp = -4931; RealProperties.min_10_exp = -4931;
} else if (targetRealSemantics == IEEEquad) { } else if (targetRealSemantics == IEEEquad) {
// FIXME: hex constants // FIXME: hex constants
RealProperties::max = RealProperties.max =
CTFloat::parse("1.18973149535723176508575932662800702e+4932"); CTFloat::parse("1.18973149535723176508575932662800702e+4932");
RealProperties::min_normal = RealProperties.min_normal =
CTFloat::parse("3.36210314311209350626267781732175260e-4932"); CTFloat::parse("3.36210314311209350626267781732175260e-4932");
RealProperties::epsilon = RealProperties.epsilon =
CTFloat::parse("1.92592994438723585305597794258492732e-34"); CTFloat::parse("1.92592994438723585305597794258492732e-34");
RealProperties::dig = 33; RealProperties.dig = 33;
RealProperties::mant_dig = 113; RealProperties.mant_dig = 113;
RealProperties::max_exp = 16384; RealProperties.max_exp = 16384;
RealProperties::min_exp = -16381; RealProperties.min_exp = -16381;
RealProperties::max_10_exp = 4932; RealProperties.max_10_exp = 4932;
RealProperties::min_10_exp = -4931; RealProperties.min_10_exp = -4931;
} else { } else {
// leave initialized with host real_t values // leave initialized with host real_t values
warning(Loc(), "unknown properties for target real type"); warning(Loc(), "unknown properties for target real type");