compiler: use nil pointer for zero length string constant
We used to pointlessly set the pointer of a zero length string
constant to point to a zero byte constant. Instead, just use nil.
Change-Id: I73fb28dcfcf547565dcab4ec26412f6e6e7ca951
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384354
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index d7b6476..3f59765 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -2123,9 +2123,15 @@
Location loc = this->location();
std::vector<Bexpression*> init(2);
- Bexpression* str_cst =
- gogo->backend()->string_constant_expression(this->val_);
- init[0] = gogo->backend()->address_expression(str_cst, loc);
+
+ if (this->val_.size() == 0)
+ init[0] = gogo->backend()->nil_pointer_expression();
+ else
+ {
+ Bexpression* str_cst =
+ gogo->backend()->string_constant_expression(this->val_);
+ init[0] = gogo->backend()->address_expression(str_cst, loc);
+ }
Btype* int_btype = Type::lookup_integer_type("int")->get_backend(gogo);
mpz_t lenval;