From fdc59f56c1038ce194b72aebe29ac9cd4150205c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 13 Apr 2019 01:03:55 +0000 Subject: compiler: improve type handling for string concat ops on constants Resolve a small problem with concatenation of string constants: in a string concat X + Y where X has named type and Y has abstract string type, insure that the result has X's type, and disable folding if the both sides have a concrete type that does not match. Fixes golang/go#31412. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/171797 From-SVN: r270336 --- gcc/go/gofrontend/expressions.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gcc/go/gofrontend/expressions.h') diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index c521d9b..43aaccf 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -230,6 +230,10 @@ class Expression static Expression* make_string(const std::string&, Location); + // Make a constant string expression with a specific string subtype. + static Expression* + make_string_typed(const std::string&, Type*, Location); + // Make an expression that evaluates to some characteristic of an string. // For simplicity, the enum values must match the field indexes in the // underlying struct. @@ -1570,9 +1574,9 @@ class Set_and_use_temporary_expression : public Expression class String_expression : public Expression { public: - String_expression(const std::string& val, Location location) + String_expression(const std::string& val, Type* type, Location location) : Expression(EXPRESSION_STRING, location), - val_(val), type_(NULL) + val_(val), type_(type) { } const std::string& -- cgit v1.1