Re: Go patch committed: Be strict about escape analysis of builtin functions

2021-08-06 Thread Ian Lance Taylor via Gcc-patches
On Wed, Aug 4, 2021 at 9:24 PM Ian Lance Taylor  wrote:
>
> This Go frontend patch by Cherry Mui makes the escape analysis pass
> stricter about builtin functions  In the places where we handle
> builtin functions, list all supported ones, and fail if an unexpected
> one is seen. So if a new builtin function is added in the future we
> can detect it, instead of silently treating it as nonescaping.
> Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
> to mainline.

Here is a follow-on patch by Cherry Mui that does the same thing for
runtime functions.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
1157b8141443caed32f0fb7ea40aa74a1ba36fac
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 19ab2de5c18..9ed527f7eb4 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-32590102c464679f845667b5554e1dcce2549ad2
+747f3a2d78c073e9b03dd81914d0edb7ddc5be14
 
 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/escape.cc b/gcc/go/gofrontend/escape.cc
index c8978ac9239..6da29edc419 100644
--- a/gcc/go/gofrontend/escape.cc
+++ b/gcc/go/gofrontend/escape.cc
@@ -1646,6 +1646,7 @@ Escape_analysis_assign::expression(Expression** pexpr)
  case Runtime::MAKECHAN:
  case Runtime::MAKECHAN64:
  case Runtime::MAKEMAP:
+ case Runtime::MAKEMAP64:
  case Runtime::MAKESLICE:
  case Runtime::MAKESLICE64:
 this->context_->track(n);
@@ -1705,8 +1706,52 @@ Escape_analysis_assign::expression(Expression** pexpr)
 }
 break;
 
+  case Runtime::MEMCMP:
+  case Runtime::DECODERUNE:
+  case Runtime::INTSTRING:
+  case Runtime::MAKEMAP_SMALL:
+  case Runtime::MAPACCESS1:
+  case Runtime::MAPACCESS1_FAST32:
+  case Runtime::MAPACCESS1_FAST64:
+  case Runtime::MAPACCESS1_FASTSTR:
+  case Runtime::MAPACCESS1_FAT:
+  case Runtime::MAPACCESS2:
+  case Runtime::MAPACCESS2_FAST32:
+  case Runtime::MAPACCESS2_FAST64:
+  case Runtime::MAPACCESS2_FASTSTR:
+  case Runtime::MAPACCESS2_FAT:
+  case Runtime::MAPASSIGN_FAST32:
+  case Runtime::MAPASSIGN_FAST64:
+  case Runtime::MAPITERINIT:
+  case Runtime::MAPITERNEXT:
+  case Runtime::MAPCLEAR:
+  case Runtime::CHANRECV2:
+  case Runtime::SELECTGO:
+  case Runtime::SELECTNBSEND:
+  case Runtime::SELECTNBRECV:
+  case Runtime::BLOCK:
+  case Runtime::IFACET2IP:
+  case Runtime::EQTYPE:
+  case Runtime::MEMCLRHASPTR:
+  case Runtime::FIELDTRACK:
+  case Runtime::BUILTIN_MEMSET:
+  case Runtime::PANIC_SLICE_CONVERT:
+// these do not escape.
+break;
+
+  case Runtime::IFACEE2E2:
+  case Runtime::IFACEI2E2:
+  case Runtime::IFACEE2I2:
+  case Runtime::IFACEI2I2:
+  case Runtime::IFACEE2T2P:
+  case Runtime::IFACEI2T2P:
+// handled in ::assign.
+break;
+
  default:
-   break;
+// should not see other runtime calls. they are not yet
+// lowered to runtime calls at this point.
+go_unreachable();
  }
  }
 else


Go patch committed: Be strict about escape analysis of builtin functions

2021-08-04 Thread Ian Lance Taylor via Gcc-patches
This Go frontend patch by Cherry Mui makes the escape analysis pass
stricter about builtin functions  In the places where we handle
builtin functions, list all supported ones, and fail if an unexpected
one is seen. So if a new builtin function is added in the future we
can detect it, instead of silently treating it as nonescaping.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
5b720746d8456986f4bb6b53d30b462f93ff58c4
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index be1a90f7aa1..394530c1cbc 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-616ee658a6238e7de53592ebda5997f6de6a00de
+b47bcf942daa9a0c252db9b57b8f138adbfcdaa2
 
 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/escape.cc b/gcc/go/gofrontend/escape.cc
index 347ac2534c9..c8978ac9239 100644
--- a/gcc/go/gofrontend/escape.cc
+++ b/gcc/go/gofrontend/escape.cc
@@ -1608,8 +1608,33 @@ Escape_analysis_assign::expression(Expression** pexpr)
 }
 break;
 
-  default:
+  case Builtin_call_expression::BUILTIN_CLOSE:
+  case Builtin_call_expression::BUILTIN_DELETE:
+  case Builtin_call_expression::BUILTIN_PRINT:
+  case Builtin_call_expression::BUILTIN_PRINTLN:
+  case Builtin_call_expression::BUILTIN_LEN:
+  case Builtin_call_expression::BUILTIN_CAP:
+  case Builtin_call_expression::BUILTIN_COMPLEX:
+  case Builtin_call_expression::BUILTIN_REAL:
+  case Builtin_call_expression::BUILTIN_IMAG:
+  case Builtin_call_expression::BUILTIN_RECOVER:
+  case Builtin_call_expression::BUILTIN_ALIGNOF:
+  case Builtin_call_expression::BUILTIN_OFFSETOF:
+  case Builtin_call_expression::BUILTIN_SIZEOF:
+// these do not escape.
+break;
+
+  case Builtin_call_expression::BUILTIN_ADD:
+  case Builtin_call_expression::BUILTIN_SLICE:
+// handled in ::assign.
 break;
+
+  case Builtin_call_expression::BUILTIN_MAKE:
+  case Builtin_call_expression::BUILTIN_NEW:
+// should have been lowered to runtime calls at this point.
+// fallthrough
+  default:
+go_unreachable();
   }
 break;
   }
@@ -2372,8 +2397,35 @@ Escape_analysis_assign::assign(Node* dst, Node* src)
 }
 break;
 
-  default:
+  case Builtin_call_expression::BUILTIN_LEN:
+  case Builtin_call_expression::BUILTIN_CAP:
+  case Builtin_call_expression::BUILTIN_COMPLEX:
+  case Builtin_call_expression::BUILTIN_REAL:
+  case Builtin_call_expression::BUILTIN_IMAG:
+  case Builtin_call_expression::BUILTIN_RECOVER:
+  case Builtin_call_expression::BUILTIN_ALIGNOF:
+  case Builtin_call_expression::BUILTIN_OFFSETOF:
+  case Builtin_call_expression::BUILTIN_SIZEOF:
+// these do not escape.
+break;
+
+  case Builtin_call_expression::BUILTIN_COPY:
+// handled in ::expression.
 break;
+
+  case Builtin_call_expression::BUILTIN_CLOSE:
+  case Builtin_call_expression::BUILTIN_DELETE:
+  case Builtin_call_expression::BUILTIN_PRINT:
+  case Builtin_call_expression::BUILTIN_PRINTLN:
+  case Builtin_call_expression::BUILTIN_PANIC:
+// these do not have result.
+// fallthrough
+  case Builtin_call_expression::BUILTIN_MAKE:
+  case Builtin_call_expression::BUILTIN_NEW:
+// should have been lowered to runtime calls at this point.
+// fallthrough
+  default:
+go_unreachable();
   }
 break;
   }