From 348181cdd4d50393c21eb60fda78af6679a640cc Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 3 Nov 2014 17:27:41 -0500 Subject: [PATCH] cmd/vet: tests for RET checking, SP checking, and leaf functions Add tests for recently introduced asm error checks in vet. This adds tests for the new warnings about functions that don't store to their return slot before returning or that store to SP-relative addresses in or beyond the argument frame. It also adds a test for leaf function handling on arm, where the link register is not implicitly saved. LGTM=rsc R=rsc CC=adg, golang-codereviews, r https://golang.org/cl/166040044 --- cmd/vet/testdata/asm.go | 2 ++ cmd/vet/testdata/asm1.s | 6 ++++++ cmd/vet/testdata/asm2.s | 6 ++++++ cmd/vet/testdata/asm3.s | 12 ++++++++++++ 4 files changed, 26 insertions(+) diff --git a/cmd/vet/testdata/asm.go b/cmd/vet/testdata/asm.go index d8df5aae..9a3d5315 100644 --- a/cmd/vet/testdata/asm.go +++ b/cmd/vet/testdata/asm.go @@ -22,6 +22,8 @@ func argiface(x interface{}, y interface { func returnint() int func returnbyte(x int) byte func returnnamed(x byte) (r1 int, r2 int16, r3 string, r4 byte) +func returnintmissing() int +func leaf(x, y int) int func noprof(x int) func dupok(x int) diff --git a/cmd/vet/testdata/asm1.s b/cmd/vet/testdata/asm1.s index 3e4fc3aa..62f423cd 100644 --- a/cmd/vet/testdata/asm1.s +++ b/cmd/vet/testdata/asm1.s @@ -27,6 +27,9 @@ TEXT ·arg1(SB),0,$0-2 TESTQ y+1(FP), AX // ERROR "invalid TESTQ of y\+1\(FP\); uint8 is 1-byte value" TESTB x+1(FP), AX // ERROR "invalid offset x\+1\(FP\); expected x\+0\(FP\)" TESTB y+2(FP), AX // ERROR "invalid offset y\+2\(FP\); expected y\+1\(FP\)" + MOVB 8(SP), AX // ERROR "8\(SP\) should be x\+0\(FP\)" + MOVB 9(SP), AX // ERROR "9\(SP\) should be y\+1\(FP\)" + MOVB 10(SP), AX // ERROR "use of 10\(SP\) points beyond argument frame" RET TEXT ·arg2(SB),0,$0-4 @@ -246,3 +249,6 @@ TEXT ·returnnamed(SB),0,$0-41 MOVB AX, r4+40(FP) MOVL AX, r1+8(FP) // ERROR "invalid MOVL of r1\+8\(FP\); int is 8-byte value" RET + +TEXT ·returnintmissing(SB),0,$0-8 + RET // ERROR "RET without writing to 8-byte ret\+0\(FP\)" diff --git a/cmd/vet/testdata/asm2.s b/cmd/vet/testdata/asm2.s index 670f54fb..c33c02a7 100644 --- a/cmd/vet/testdata/asm2.s +++ b/cmd/vet/testdata/asm2.s @@ -26,6 +26,9 @@ TEXT ·arg1(SB),0,$0-2 TESTQ y+1(FP), AX // ERROR "invalid TESTQ of y\+1\(FP\); uint8 is 1-byte value" TESTB x+1(FP), AX // ERROR "invalid offset x\+1\(FP\); expected x\+0\(FP\)" TESTB y+2(FP), AX // ERROR "invalid offset y\+2\(FP\); expected y\+1\(FP\)" + MOVB 4(SP), AX // ERROR "4\(SP\) should be x\+0\(FP\)" + MOVB 5(SP), AX // ERROR "5\(SP\) should be y\+1\(FP\)" + MOVB 6(SP), AX // ERROR "use of 6\(SP\) points beyond argument frame" RET TEXT ·arg2(SB),0,$0-4 @@ -249,3 +252,6 @@ TEXT ·returnnamed(SB),0,$0-21 MOVB AX, r4+20(FP) MOVQ AX, r1+4(FP) // ERROR "invalid MOVQ of r1\+4\(FP\); int is 4-byte value" RET + +TEXT ·returnintmissing(SB),0,$0-4 + RET // ERROR "RET without writing to 4-byte ret\+0\(FP\)" diff --git a/cmd/vet/testdata/asm3.s b/cmd/vet/testdata/asm3.s index 4c2643b0..3d69356a 100644 --- a/cmd/vet/testdata/asm3.s +++ b/cmd/vet/testdata/asm3.s @@ -14,6 +14,9 @@ TEXT ·arg1(SB),0,$0-2 MOVW y+1(FP), AX // ERROR "invalid MOVW of y\+1\(FP\); uint8 is 1-byte value" MOVB x+1(FP), AX // ERROR "invalid offset x\+1\(FP\); expected x\+0\(FP\)" MOVB y+2(FP), AX // ERROR "invalid offset y\+2\(FP\); expected y\+1\(FP\)" + MOVB 8(R13), AX // ERROR "8\(R13\) should be x\+0\(FP\)" + MOVB 9(R13), AX // ERROR "9\(R13\) should be y\+1\(FP\)" + MOVB 10(R13), AX // ERROR "use of 10\(R13\) points beyond argument frame" RET TEXT ·arg2(SB),0,$0-4 @@ -164,3 +167,12 @@ TEXT ·returnnamed(SB),0,$0-21 MOVB AX, r4+20(FP) MOVB AX, r1+4(FP) // ERROR "invalid MOVB of r1\+4\(FP\); int is 4-byte value" RET + +TEXT ·returnintmissing(SB),0,$0-4 + RET // ERROR "RET without writing to 4-byte ret\+0\(FP\)" + +TEXT ·leaf(SB),0,$-4-12 + MOVW x+0(FP), AX + MOVW y+4(FP), AX + MOVW AX, ret+8(FP) + RET