diff options
author | Ian Lance Taylor <iant@golang.org> | 2022-02-08 20:16:38 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2022-02-09 14:13:33 -0800 |
commit | 2e2b861e8941c4e9b36b88e9c562642b1aba6eaf (patch) | |
tree | 1875086aacad0b6a90747d81b4040d7f85727fcc | |
parent | 70feb6839fe1f13982eb03096bd1140b59881b76 (diff) | |
download | gcc-2e2b861e8941c4e9b36b88e9c562642b1aba6eaf.zip gcc-2e2b861e8941c4e9b36b88e9c562642b1aba6eaf.tar.gz gcc-2e2b861e8941c4e9b36b88e9c562642b1aba6eaf.tar.bz2 |
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.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384354
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 3ea7aed..8cbd0c1 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -7dffb933d33ff288675c8094d05c31b35cbf7e4d +263e8d2a2ab57c6f2b3035f370d40476bda87c9f The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index d7b6476..3f59765 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -2123,9 +2123,15 @@ String_expression::do_get_backend(Translate_context* context) 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; |