Skip to content
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

gccgo: internal compiler error declaring method without body #27994

Closed
griesemer opened this issue Oct 3, 2018 · 4 comments
Closed

gccgo: internal compiler error declaring method without body #27994

griesemer opened this issue Oct 3, 2018 · 4 comments
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

It's not clear that this code is permitted in the first place, but gccgo shouldn't crash.

$ cat x.go
package p

type T struct{}
type T1 = *T

func (T1) m() int

var _ = (&T{}).m()

cmd/compile accepts this. gccgo crashes (and go/types reports an error - no such method).

$ gccgo -c x.go
go1: internal compiler error: in add_method_declaration, at go/gofrontend/types.cc:9927
0x731cbd Named_type::add_method_declaration(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Package*, Function_type*, Location)
	/tmp/go-build-release/gccgo-srcdir/gcc/go/gofrontend/types.cc:9927
0x719c51 Parse::function_decl(unsigned int)
	/tmp/go-build-release/gccgo-srcdir/gcc/go/gofrontend/parse.cc:2432
0x71a247 Parse::program()
	/tmp/go-build-release/gccgo-srcdir/gcc/go/gofrontend/parse.cc:5807
0x6d5304 go_parse_input_files(char const**, unsigned int, bool, bool)
	/tmp/go-build-release/gccgo-srcdir/gcc/go/gofrontend/go.cc:79
0x6d0caf go_langhook_parse_file
	/tmp/go-build-release/gccgo-srcdir/gcc/go/go-lang.c:330
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://go.ext.google.com/go/> for instructions.

The crash also appears if T1 = T and the literal is just T{} rather than &T{}.

$ gccgo -v
Using built-in specs.
COLLECT_GCC=/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/gccgo
COLLECT_LTO_WRAPPER=/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../libexec/gcc/x86_64-unknown-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /tmp/go-build-release/gccgo-srcdir/configure --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --prefix=/tmp/go-build-release/gccgo-installdir/x86/gcc/x86 --target=x86_64-unknown-linux-gnu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-c99 --enable-long-long --with-gnu-as --with-gnu-ld --disable-canonical-prefixes --enable-shared=libgcc,libmudflap,libssp,libstdc++,libgo,libffi,libatomic,libbacktrace --with-pic=libgfortran,libquadmath --enable-languages=c,go --with-sysroot=/usr/grte/v4 --with-build-sysroot=/google/src/files/185756253/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4 --with-native-system-header-dir=/include --with-runtime-root-prefix=/usr/grte/v4 --with-local-prefix=/ --with-bugurl=http://go.ext.google.com/go/ --with-pkgversion=google-gccgo-263179 --enable-clocale=gnu --enable-linker-build-id --disable-cloog 'MAKE_BOOT_CFLAGS=-g -O2 -static-libgcc -static-libstdc++' AR_FOR_TARGET=/tmp/go-build-release/bin/x86/dar RANLIB_FOR_TARGET=/tmp/go-build-release/bin/x86/dranlib --enable-tls --disable-bootstrap --disable-initfini-array --disable-multilib
Thread model: posix
gcc version 9.0.0 20180731 (experimental) (google-gccgo-263179) 
COMPILER_PATH=/google/src/files/215638664/depot/google3/third_party/crosstool/v18/stable/wrappers/x86_64-grtev4-linux-gnu/bin/:/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../libexec/gcc/x86_64-unknown-linux-gnu/9.0.0/:/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../libexec/gcc/
LIBRARY_PATH=/google/src/files/215638664/depot/google3/third_party/crosstool/v18/stable/wrappers/x86_64-grtev4-linux-gnu/bin/:/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0/:/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/:/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0/../../../../lib64/:/google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4/lib/../lib64/:/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0/../../../:/google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4/lib/
COLLECT_GCC_OPTIONS='-fsplit-stack' '-B' '/google/src/files/215638664/depot/google3/third_party/crosstool/v18/stable/wrappers/x86_64-grtev4-linux-gnu/bin/' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /google/src/files/215638664/depot/google3/third_party/crosstool/v18/stable/wrappers/x86_64-grtev4-linux-gnu/bin/ld -plugin /google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../libexec/gcc/x86_64-unknown-linux-gnu/9.0.0/liblto_plugin.so -plugin-opt=/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../libexec/gcc/x86_64-unknown-linux-gnu/9.0.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccoxSbaH.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4 --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /usr/grte/v4/lib64/ld-linux-x86-64.so.2 /google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4/lib/../lib64/crt1.o /google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4/lib/../lib64/crti.o /google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0/crtbegin.o -L/google/src/files/215638664/depot/google3/third_party/crosstool/v18/stable/wrappers/x86_64-grtev4-linux-gnu/bin -L/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0 -L/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc -L/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0/../../../../lib64 -L/google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4/lib/../lib64 -L/google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0/../../.. -L/google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4/lib -lgobegin -Bstatic -lgo -Bdynamic -lpthread -lm --wrap=pthread_create -lgcc_s -lgcc -lc -lgcc_s -lgcc /google/src/files/215638664/depot/google3/third_party/go/gccgo/gcc/x86/bin/../lib/gcc/x86_64-unknown-linux-gnu/9.0.0/crtend.o /google/src/files/215638664/depot/google3/third_party/grte/v4_x86/release/usr/grte/v4/lib/../lib64/crtn.o
/tmp/go-build-release/gccgo-srcdir/libgo/go/runtime/proc.go:209: error: undefined reference to '__go_init_main'
/tmp/go-build-release/gccgo-srcdir/libgo/go/runtime/proc.go:225: error: undefined reference to 'main.main'
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 3, 2018
@griesemer griesemer added this to the Gccgo milestone Oct 3, 2018
@gopherbot gopherbot removed the NeedsFix The path to resolution is known, but the work has not been done. label Oct 3, 2018
@griesemer griesemer changed the title gccgo: internal compiler error declaring method with receiver base type that is an alias gccgo: internal compiler error declaring method without body Oct 3, 2018
@griesemer
Copy link
Contributor Author

Follow-up. The crash disappears if there's a method body:

$ cat x.go
package p

type T struct{}
type T1 = *T

func (T1) m() int { return 0 }

var _ = (&T{}).m()

compiles with an error message:

$ gccgo -c x.go
x.go:6:7: error: invalid receiver type (receiver must be a named type)
 func (T1) m() int { return 0 }
       ^
x.go:8:15: error: reference to undefined field or method 'm'
 var _ = (&T{}).m()
               ^

@beoran
Copy link

beoran commented Oct 4, 2018

As the spec states "A function declaration may omit the body. Such a declaration provides the signature for a function implemented outside Go, such as an assembly routine." I think it should be the same for methods without body. They are needed to allow implementation of methods in C or assembler.

@thanm
Copy link
Contributor

thanm commented Oct 5, 2018

I will take a look.

@gopherbot
Copy link

Change https://golang.org/cl/160459 mentions this issue: compiler: support alias to pointer type as receiver in method decleration

hjl-tools pushed a commit to hjl-tools/gcc that referenced this issue Feb 1, 2019
…ation

    
    Fixes golang/go#27994.
    
    Reviewed-on: https://go-review.googlesource.com/c/160459


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@268450 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Feb 1, 2020
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