Skip to content

gccgo: internal compiler error with cyclic function declaration (esoteric) #25680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
griesemer opened this issue Jun 1, 2018 · 5 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@griesemer
Copy link
Contributor

With

$ gccgo --version
gccgo (google-gccgo-257955) 8.0.1 20180223 (experimental)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

compiling the following program:

$ cat x.go
package main

func g() [g()[0]]int { panic(0) }

func main() {
}

leads to an internal compiler error:

$ gccgo x.go
gccgo: internal compiler error: Segmentation fault signal terminated program go1
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://go.ext.google.com/go/> for instructions.

cc: @thanm

@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 1, 2018
@griesemer griesemer added this to the Gccgo milestone Jun 1, 2018
@ianlancetaylor
Copy link
Contributor

I hope that program is not valid Go.

@griesemer
Copy link
Contributor Author

I don't think it is. But it probably shouldn't crash. But certainly not important in any case. Just reporting another test case for the cycle test suite...

@thanm
Copy link
Contributor

thanm commented Jun 1, 2018

Related to #25315, #25677, #25299. Should be able to fix them together (at least for gccgo).

@deanveloper
Copy link

I hope that program is not valid Go.

It isn't. Array lengths are defined as follows:

The length is part of the array's type; it must evaluate to a non-negative constant representable by a value of type int.

Since [g()[0]]int is an array, and g()[0] is not a constant this is not valid Go.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/115796 mentions this issue: compiler: fix crashes on cyclic var/type references

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Jun 4, 2018
    
    This patch fixes type traversal to avoid compiler crashes for test
    cases where a type T includes an expression that refers back to the
    type without actually explicitly mentioning T. Examples include
    
      var x [uintptr(unsafe.Sizeof(&x))]byte
      var a [len(a)]int
    
    The fix involves expanding the set of types that the traversal code
    "remembers" (to avoid cycles) to include array types, and introducing an
    additional guard in Builtin_call_expression::do_is_constant to catch
    cyclic type constructs.
    
    Fixes golang/go#25299
    Fixes golang/go#25679
    Fixes golang/go#25315
    Fixes golang/go#25680
    
    Reviewed-on: https://go-review.googlesource.com/115796


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@261168 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Jun 4, 2019
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
    
    This patch fixes type traversal to avoid compiler crashes for test
    cases where a type T includes an expression that refers back to the
    type without actually explicitly mentioning T. Examples include
    
      var x [uintptr(unsafe.Sizeof(&x))]byte
      var a [len(a)]int
    
    The fix involves expanding the set of types that the traversal code
    "remembers" (to avoid cycles) to include array types, and introducing an
    additional guard in Builtin_call_expression::do_is_constant to catch
    cyclic type constructs.
    
    Fixes golang/go#25299
    Fixes golang/go#25679
    Fixes golang/go#25315
    Fixes golang/go#25680
    
    Reviewed-on: https://go-review.googlesource.com/115796

From-SVN: r261168
@rsc rsc unassigned thanm Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants