https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90116

            Bug ID: 90116
           Summary: Segmentation fault and what appears to be an
                    implementation error in gofrontend (parse.cc)
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: 22374604 at sun dot ac.za
                CC: cmang at google dot com
  Target Milestone: ---

Created attachment 46179
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46179&action=edit
Program that causes segmentation fault

My research entails systematic generation of test cases from grammars. We
picked the golang from the antlr v4 grammar repository, avilable at
https://github.com/antlr/grammars-v4,which is a translation from the golang
language specification available at https://golang.org/ref/spec . Here I
present two issues I uncovered.

1. The following generated programs causes internalcompiler error:

package A; var A[A] A;

Compilation of the above program:
gccgo-8.2 -c -Wall -Wextra
/home/max/experiments/go/pos/pair/4730a8a0-603a-11e9-b473-8f102747f394.go

output:
gccgo-8.2: internal compiler error: Segmentation fault signal terminated
program go1

2. Implementation error of the parser in gcc/go/gofrontend/parse.cc

ggc-go  also throws a syntax error on one of the generated programs below:

package A; const(B; C;);

Antlr v4 consumes the program correctly without throwing out any parse errors
and gccgo-8.2 compalins that '=' is expected.

One rule is of interest 
ConstSpec = IdentifierList [ [ CompleteType ] "=" ExpressionList ] .

The above rule is from golang language specification and also included
commented in file parse.cc at line 1440 the method that implements the rule
follows at 1442. And it shows that '=' is optional. The go compiler implements
the hand written recursive descent parser. I came to think that the parser in
the gccgo does not implement the grammar (language spec) .

Rules involving that program to show its syntax is valid:
ConstDecl      = "const" ( ConstSpec | "(" { ConstSpec ";" } ")" ) .
ConstSpec = IdentifierList [ [ CompleteType ] "=" ExpressionList ] .
IdentifierList = identifier { "," identifier } .

Reply via email to