diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-16 22:10:26 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-16 22:10:26 +0000 |
commit | 60a3da27fef24089ae0b77cc2a006c46419882a5 (patch) | |
tree | 1393fc131050d4a0b694f9a22d6ad012753f3bb2 /gcc | |
parent | 539b471b67c7e7076c7c4da34c2ba28fdf816cb0 (diff) | |
download | gcc-60a3da27fef24089ae0b77cc2a006c46419882a5.zip gcc-60a3da27fef24089ae0b77cc2a006c46419882a5.tar.gz gcc-60a3da27fef24089ae0b77cc2a006c46419882a5.tar.bz2 |
compiler: Lower constant string comparisons.
From-SVN: r184316
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 0b53f72..20c49f1 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -5824,15 +5824,46 @@ Binary_expression::do_lower(Gogo* gogo, Named_object*, } // String constant expressions. - if (op == OPERATOR_PLUS - && left->type()->is_string_type() - && right->type()->is_string_type()) + if (left->type()->is_string_type() && right->type()->is_string_type()) { std::string left_string; std::string right_string; if (left->string_constant_value(&left_string) && right->string_constant_value(&right_string)) - return Expression::make_string(left_string + right_string, location); + { + if (op == OPERATOR_PLUS) + return Expression::make_string(left_string + right_string, + location); + else if (is_comparison) + { + int cmp = left_string.compare(right_string); + bool r; + switch (op) + { + case OPERATOR_EQEQ: + r = cmp == 0; + break; + case OPERATOR_NOTEQ: + r = cmp != 0; + break; + case OPERATOR_LT: + r = cmp < 0; + break; + case OPERATOR_LE: + r = cmp <= 0; + break; + case OPERATOR_GT: + r = cmp > 0; + break; + case OPERATOR_GE: + r = cmp >= 0; + break; + default: + go_unreachable(); + } + return Expression::make_boolean(r, location); + } + } } // Special case for shift of a floating point constant. |