From 7a98315c9615b2ae75398df5b0f9b2c0c57b2844 Mon Sep 17 00:00:00 2001 From: Ken Thompson Date: Tue, 28 Apr 2009 17:20:18 -0700 Subject: [PATCH] allow "defer close(chan)" bug found by anton R=r OCL=28001 CL=28001 --- src/cmd/gc/go.y | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 74475b4b37..4c326f1e72 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -54,7 +54,7 @@ %type if_stmt if_body if_header select_stmt condition %type simple_stmt osimple_stmt range_stmt semi_stmt %type expr uexpr pexpr expr_list oexpr oexpr_list expr_list_r -%type exprsym3_list_r exprsym3 +%type exprsym3_list_r exprsym3 pseudocall %type name labelname onew_name new_name new_name_list_r new_field %type vardcl_list_r vardcl Avardcl Bvardcl %type interfacedcl_list_r interfacedcl interfacedcl1 @@ -547,15 +547,13 @@ semi_stmt: { $$ = nod(OCONTINUE, $2, N); } -| LGO pexpr '(' oexpr_list ')' +| LGO pseudocall { - $$ = nod(OCALL, $2, $4); - $$ = nod(OPROC, $$, N); + $$ = nod(OPROC, $2, N); } -| LDEFER pexpr '(' oexpr_list ')' +| LDEFER pseudocall { - $$ = nod(OCALL, $2, $4); - $$ = nod(ODEFER, $$, N); + $$ = nod(ODEFER, $2, N); } | LGOTO new_name { @@ -823,6 +821,22 @@ uexpr: $$ = nod(ORECV, $2, N); } +/* + * call-like statements that + * can be preceeded by 'defer' and 'go' + */ +pseudocall: + pexpr '(' oexpr_list ')' + { + $$ = unsafenmagic($1, $3); + if($$ == N) + $$ = nod(OCALL, $1, $3); + } +| LCLOSE '(' expr ')' + { + $$ = nod(OCLOSE, $3, N); + } + pexpr: LLITERAL { @@ -881,20 +895,11 @@ pexpr: { $$ = nod(OSLICE, $1, $3); } -| pexpr '(' oexpr_list ')' - { - $$ = unsafenmagic($1, $3); - if($$ == N) - $$ = nod(OCALL, $1, $3); - } +| pseudocall | LLEN '(' expr ')' { $$ = nod(OLEN, $3, N); } -| LCLOSE '(' expr ')' - { - $$ = nod(OCLOSE, $3, N); - } | LCLOSED '(' expr ')' { $$ = nod(OCLOSED, $3, N); -- 2.48.1