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

cmd/compile: concurrent compilation of generated functions generates an extra nil check #20242

Closed
josharian opened this issue May 4, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@josharian
Copy link
Contributor

commented May 4, 2017

This issue assumes CL 41503 has gone in.

package main

func f(...interface{}) {}

func main() {
	f(1, 2)
}

With -c, the generated code contains an extra nil check.

Before:

type..hash.[2]interface {} STEXT dupok size=110 args=0x18 locals=0x28
	0x0000 00000 (<autogenerated>:1)	TEXT	type..hash.[2]interface {}(SB), DUPOK, $40-24
	0x0000 00000 (<autogenerated>:1)	MOVQ	(TLS), CX
	0x0009 00009 (<autogenerated>:1)	CMPQ	SP, 16(CX)
	0x000d 00013 (<autogenerated>:1)	JLS	103
	0x000f 00015 (<autogenerated>:1)	SUBQ	$40, SP
	0x0013 00019 (<autogenerated>:1)	MOVQ	BP, 32(SP)
	0x0018 00024 (<autogenerated>:1)	LEAQ	32(SP), BP
	0x001d 00029 (<autogenerated>:1)	FUNCDATA	$0, gclocals·d4dc2f11db048877dbc0f60a22b4adb3(SB)
	0x001d 00029 (<autogenerated>:1)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
	0x001d 00029 (<autogenerated>:1)	MOVL	$0, AX
	0x001f 00031 (<autogenerated>:1)	MOVQ	"".h+56(SP), CX
	0x0024 00036 (<autogenerated>:1)	JMP	82
	0x0026 00038 (<autogenerated>:1)	MOVQ	AX, "".i+24(SP)
	0x002b 00043 (<autogenerated>:1)	SHLQ	$4, AX
	0x002f 00047 (<autogenerated>:1)	MOVQ	"".p+48(SP), BX
	0x0034 00052 (<autogenerated>:1)	ADDQ	BX, AX
	0x0037 00055 (<autogenerated>:1)	MOVQ	AX, (SP)
	0x003b 00059 (<autogenerated>:1)	MOVQ	CX, 8(SP)
	0x0040 00064 (<autogenerated>:1)	PCDATA	$0, $0
	0x0040 00064 (<autogenerated>:1)	CALL	runtime.nilinterhash(SB)
	0x0045 00069 (<autogenerated>:1)	MOVQ	16(SP), CX
	0x004a 00074 (<autogenerated>:1)	MOVQ	"".i+24(SP), AX
	0x004f 00079 (<autogenerated>:1)	INCQ	AX
	0x0052 00082 (<autogenerated>:1)	CMPQ	AX, $2
	0x0056 00086 (<autogenerated>:1)	JLT	38
	0x0058 00088 (<autogenerated>:1)	MOVQ	CX, "".~r2+64(SP)
	0x005d 00093 (<autogenerated>:1)	MOVQ	32(SP), BP
	0x0062 00098 (<autogenerated>:1)	ADDQ	$40, SP
	0x0066 00102 (<autogenerated>:1)	RET
	0x0067 00103 (<autogenerated>:1)	NOP
	0x0067 00103 (<autogenerated>:1)	PCDATA	$0, $-1
	0x0067 00103 (<autogenerated>:1)	CALL	runtime.morestack_noctxt(SB)
	0x006c 00108 (<autogenerated>:1)	JMP	0

After:

type..hash.[2]interface {} STEXT dupok size=112 args=0x18 locals=0x28
	0x0000 00000 (<autogenerated>:1)	TEXT	type..hash.[2]interface {}(SB), DUPOK, $40-24
	0x0000 00000 (<autogenerated>:1)	MOVQ	(TLS), CX
	0x0009 00009 (<autogenerated>:1)	CMPQ	SP, 16(CX)
	0x000d 00013 (<autogenerated>:1)	JLS	105
	0x000f 00015 (<autogenerated>:1)	SUBQ	$40, SP
	0x0013 00019 (<autogenerated>:1)	MOVQ	BP, 32(SP)
	0x0018 00024 (<autogenerated>:1)	LEAQ	32(SP), BP
	0x001d 00029 (<autogenerated>:1)	FUNCDATA	$0, gclocals·d4dc2f11db048877dbc0f60a22b4adb3(SB)
	0x001d 00029 (<autogenerated>:1)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
	0x001d 00029 (<autogenerated>:1)	MOVL	$0, AX
	0x001f 00031 (<autogenerated>:1)	MOVQ	"".h+56(SP), CX
	0x0024 00036 (<autogenerated>:1)	JMP	84
	0x0026 00038 (<autogenerated>:1)	MOVQ	AX, "".i+24(SP)
	0x002b 00043 (<autogenerated>:1)	MOVQ	"".p+48(SP), DX
	0x0030 00048 (<autogenerated>:1)	TESTB	AL, (DX)
	0x0032 00050 (<autogenerated>:1)	SHLQ	$4, AX
	0x0036 00054 (<autogenerated>:1)	ADDQ	DX, AX
	0x0039 00057 (<autogenerated>:1)	MOVQ	AX, (SP)
	0x003d 00061 (<autogenerated>:1)	MOVQ	CX, 8(SP)
	0x0042 00066 (<autogenerated>:1)	PCDATA	$0, $0
	0x0042 00066 (<autogenerated>:1)	CALL	runtime.nilinterhash(SB)
	0x0047 00071 (<autogenerated>:1)	MOVQ	16(SP), CX
	0x004c 00076 (<autogenerated>:1)	MOVQ	"".i+24(SP), AX
	0x0051 00081 (<autogenerated>:1)	INCQ	AX
	0x0054 00084 (<autogenerated>:1)	CMPQ	AX, $2
	0x0058 00088 (<autogenerated>:1)	JLT	38
	0x005a 00090 (<autogenerated>:1)	MOVQ	CX, "".~r2+64(SP)
	0x005f 00095 (<autogenerated>:1)	MOVQ	32(SP), BP
	0x0064 00100 (<autogenerated>:1)	ADDQ	$40, SP
	0x0068 00104 (<autogenerated>:1)	RET
	0x0069 00105 (<autogenerated>:1)	NOP
	0x0069 00105 (<autogenerated>:1)	PCDATA	$0, $-1
	0x0069 00105 (<autogenerated>:1)	CALL	runtime.morestack_noctxt(SB)
	0x006e 00110 (<autogenerated>:1)	JMP	0

But the -c flag must produce identical output.

Found by go-fuzz.

@josharian josharian added this to the Go1.9 milestone May 4, 2017

@josharian josharian self-assigned this May 4, 2017

@gopherbot

This comment has been minimized.

Copy link

commented May 4, 2017

CL https://golang.org/cl/42591 mentions this issue.

@gopherbot gopherbot closed this in 53e62ab May 5, 2017

@golang golang locked and limited conversation to collaborators May 5, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.