Commit 9146ac14 authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/gc: do not overflow parser stack on a long chain of else if.

Fixes #2615.

R=dave, minux.ma, iant, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6847078
parent 53d091c5
......@@ -57,7 +57,7 @@ static void fixlbrace(int);
%type <node> compound_stmt dotname embed expr complitexpr
%type <node> expr_or_type
%type <node> fndcl hidden_fndcl fnliteral
%type <node> for_body for_header for_stmt if_header if_stmt else non_dcl_stmt
%type <node> for_body for_header for_stmt if_header if_stmt non_dcl_stmt
%type <node> interfacedcl keyval labelname name
%type <node> name_or_type non_expr_type
%type <node> new_name dcl_name oexpr typedclname
......@@ -70,7 +70,7 @@ static void fixlbrace(int);
%type <list> xdcl fnbody fnres loop_body dcl_name_list
%type <list> new_name_list expr_list keyval_list braced_keyval_list expr_or_type_list xdcl_list
%type <list> oexpr_list caseblock_list stmt_list oarg_type_list_ocomma arg_type_list
%type <list> oexpr_list caseblock_list elseif elseif_list else stmt_list oarg_type_list_ocomma arg_type_list
%type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list
%type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list
......@@ -661,25 +661,56 @@ if_stmt:
{
$3->nbody = $5;
}
else
elseif_list else
{
popdcl();
Node *n;
NodeList *nn;
$$ = $3;
if($7 != N)
$$->nelse = list1($7);
n = $3;
popdcl();
for(nn = concat($7, $8); nn; nn = nn->next) {
if(nn->n->op == OIF)
popdcl();
n->nelse = list1(nn->n);
n = nn->n;
}
}
else:
elseif:
LELSE LIF
{
$$ = N;
markdcl();
}
| LELSE if_stmt
if_header loop_body
{
$$ = $2;
if($4->ntest == N)
yyerror("missing condition in if statement");
$4->nbody = $5;
$$ = list1($4);
}
elseif_list:
{
$$ = nil;
}
| elseif_list elseif
{
$$ = concat($1, $2);
}
else:
{
$$ = nil;
}
| LELSE compound_stmt
{
$$ = $2;
NodeList *node;
node = mal(sizeof *node);
node->n = $2;
node->end = node;
$$ = node;
}
switch_stmt:
......
This diff is collapsed.
/* A Bison parser, made by GNU Bison 2.3. */
/* A Bison parser, made by GNU Bison 2.6.5. */
/* Skeleton interface for Bison's Yacc-like parsers in C
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -16,9 +15,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
......@@ -33,6 +30,16 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_Y_TAB_H_INCLUDED
# define YY_YY_Y_TAB_H_INCLUDED
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
......@@ -143,25 +150,42 @@
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 28 "go.y"
{
/* Line 2042 of yacc.c */
#line 28 "go.y"
Node* node;
NodeList* list;
Type* type;
Sym* sym;
struct Val val;
int i;
}
/* Line 1529 of yacc.c. */
#line 160 "y.tab.h"
YYSTYPE;
/* Line 2042 of yacc.c */
#line 169 "y.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
extern YYSTYPE yylval;
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (void);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_YY_Y_TAB_H_INCLUDED */
......@@ -71,6 +71,6 @@ static struct {
112, LNAME,
"nested func not allowed",
615, ';',
639, ';',
"else must be followed by if or statement block"
};
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment