Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(111)

Issue 5784046: code review 5784046: go/parser: avoid endless loop in case of internal error (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 9 months ago by gri
Modified:
13 years, 9 months ago
Reviewers:
CC:
rsc, rsc1, golang-dev
Visibility:
Public.

Description

go/parser: avoid endless loop in case of internal error Factored the error synchronization code into two functions syncStmt and syncDecl. Because they may return w/o advancing the scanner, there is potential for endless loops across multiple parse functions; typically caused by an incorrect token list in these functions (e.g., adding token.ELSE to syncStmt will cause the parser to go into an endless loop for test/syntax/semi7.go without this mechanism). This would indicate a compiler bug, exposed only in an error situation for very specific source files. Added a mechanism to force scanner advance if an endless loop is detected. As a result, error recovery will be less good in those cases, but the parser reported a source error already and at least doesn't get stuck.

Patch Set 1 #

Patch Set 2 : diff -r 097e02a1815a https://code.google.com/p/go #

Patch Set 3 : diff -r 097e02a1815a https://code.google.com/p/go #

Patch Set 4 : diff -r 097e02a1815a https://code.google.com/p/go #

Total comments: 1

Patch Set 5 : diff -r 7f518fff6a72 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+66 lines, -30 lines) Patch
M src/pkg/go/parser/parser.go View 1 2 3 4 9 chunks +66 lines, -30 lines 0 comments Download

Messages

Total messages: 3
gri
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
13 years, 9 months ago (2012-03-08 00:52:16 UTC) #1
rsc1
LGTM http://codereview.appspot.com/5784046/diff/4003/src/pkg/go/parser/parser.go File src/pkg/go/parser/parser.go (right): http://codereview.appspot.com/5784046/diff/4003/src/pkg/go/parser/parser.go#newcode48 src/pkg/go/parser/parser.go:48: synCnt int // number of calls to syncXXX ...
13 years, 9 months ago (2012-03-08 02:16:44 UTC) #2
gri
13 years, 9 months ago (2012-03-08 05:28:53 UTC) #3
*** Submitted as http://code.google.com/p/go/source/detail?r=ee68d043e7f5 ***

go/parser: avoid endless loop in case of internal error

Factored the error synchronization code into two functions
syncStmt and syncDecl. Because they may return w/o advancing
the scanner, there is potential for endless loops across
multiple parse functions; typically caused by an incorrect
token list in these functions (e.g., adding token.ELSE to
syncStmt will cause the parser to go into an endless loop
for test/syntax/semi7.go without this mechanism). This would
indicate a compiler bug, exposed only in an error situation
for very specific source files. Added a mechanism to force
scanner advance if an endless loop is detected. As a result,
error recovery will be less good in those cases, but the parser
reported a source error already and at least doesn't get stuck.

R=rsc, rsc
CC=golang-dev
http://codereview.appspot.com/5784046
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b