diff options
author | Ian Lance Taylor <iant@google.com> | 2012-11-16 16:30:35 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2012-11-16 16:30:35 +0000 |
commit | 9f576894844fd62bea431399747b5217b73779cd (patch) | |
tree | 192a7c4a81fe514460415c427977d664b165da0e /gcc/go | |
parent | a2544bf7b26ea34feadc9b9bb3a218c7b1ba5f90 (diff) |
compiler: don't remove floating point conversion of typed constant
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@193565 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 8fe61462aee..9d3b8f56655 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -2962,6 +2962,46 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*, { if (!nc.set_type(type, true, location)) return Expression::make_error(location); + + // Don't simply convert to or from a float or complex type + // with a different size. That may change the value. + Type* vtype = val->type(); + if (vtype->is_abstract()) + ; + else if (type->float_type() != NULL) + { + if (vtype->float_type() != NULL) + { + if (type->float_type()->bits() != vtype->float_type()->bits()) + return this; + } + else if (vtype->complex_type() != NULL) + { + if (type->float_type()->bits() * 2 + != vtype->complex_type()->bits()) + return this; + } + } + else if (type->complex_type() != NULL) + { + if (vtype->complex_type() != NULL) + { + if (type->complex_type()->bits() + != vtype->complex_type()->bits()) + return this; + } + else if (vtype->float_type() != NULL) + { + if (type->complex_type()->bits() + != vtype->float_type()->bits() * 2) + return this; + } + } + else if (vtype->float_type() != NULL) + return this; + else if (vtype->complex_type() != NULL) + return this; + return nc.expression(location); } } |