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: unexpected error on inlined routine calling varargs function #32922

Closed
thanm opened this issue Jul 3, 2019 · 2 comments
Closed

gccgo: unexpected error on inlined routine calling varargs function #32922

thanm opened this issue Jul 3, 2019 · 2 comments
Milestone

Comments

@thanm
Copy link
Contributor

thanm commented Jul 3, 2019

What version of Go are you using (go version)?

$ go version
gccgo (GCC) 10.0.0 20190703 (experimental)

What did you do?

Compile these two packages:

a.go

package a

func A() int {
	return p("count")
}

func p(which string, args ...string) int {
	switch which {
	case "count", "something":
		return 1
	default:
		return 2
	}
}

b.go

package b

import "a"

func B() int {
	return 99 + a.A()
}

using "go install a" then "go build b"

What did you expect to see?

Clean build

What did you see instead?

When compiling "b", this error:

$ go build .
# b
.../src/a/a.go:4:0: error: argument 2 has incompatible type

[Note that even though we are compiling b.go, the error is being reported in a.go]. Error is happening during lowering. At the call to go_error_at we are in:

#1  Call_expression::check_argument_type (...) go/expressions.cc:11861
#2  Call_expression::lower_varargs (...) go/expressions.cc:10914
#3  Call_expression::do_lower (...) go/expressions.cc:10763

It looks as though the argument type here is nil_type", and the parameter type is string type:

(gdb) p debug_go_type(parameter_type)
      T0   0x555559ad9fa0  'string' -> string
      T1   0x555559a4e000  string
$10 = void
(gdb) p debug_go_type(argument_type)
      T0   0x555559a4e0a0  nil_type
$11 = void
(gdb) 

Looking at the export data for the function:

func A () ($ret0 <type -11>) <inl:86>
// .../src/a/a.go:3
{ //4
$ret0 = .p("count", $nil) //4
return //4
} //0
@gopherbot gopherbot added this to the Gccgo milestone Jul 3, 2019
@gopherbot
Copy link

Change https://golang.org/cl/184918 mentions this issue: test: add new test case for gccgo compiler bug

@thanm thanm self-assigned this Jul 3, 2019
@gopherbot
Copy link

Change https://golang.org/cl/184919 mentions this issue: compiler: set varargs lowered for imported call expressions

jpf91 pushed a commit to D-Programming-GDC/gcc that referenced this issue Jul 4, 2019
    
    Fix compiler buglet: varargs lowering happens before inlinable
    function bodies are written out to export data, so set the "varargs
    lowered" flag on call expressions that we import.
    
    Fixes golang/go#32922
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/184919


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@273026 138bc75d-0d04-0410-961f-82ee72b054a4
gopherbot pushed a commit that referenced this issue Jul 8, 2019
Test case that causes incorrect compiler error from gccgo.

Updates #32922

Change-Id: I59432a8e8770cf03eda293f6d110c081c18fa88b
Reviewed-on: https://go-review.googlesource.com/c/go/+/184918
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
@golang golang locked and limited conversation to collaborators Jul 2, 2020
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
    
    Fix compiler buglet: varargs lowering happens before inlinable
    function bodies are written out to export data, so set the "varargs
    lowered" flag on call expressions that we import.
    
    Fixes golang/go#32922
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/184919

From-SVN: r273026
@rsc rsc unassigned thanm Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants