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/vet: asmdecl flag scans code in multiline comments #58866

Open
WojciechMula opened this issue Mar 4, 2023 · 5 comments
Open

cmd/vet: asmdecl flag scans code in multiline comments #58866

WojciechMula opened this issue Mar 4, 2023 · 5 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@WojciechMula
Copy link

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

$ go version
go version go1.20 linux/amd64

What did you do?

This is the repro:

~/tmp/govet$ cat go.mod 
module main

~/tmp/govet$ cat main.go 
package main

// go:noescape
// go:nosplit
func procedure()

func main() {
    procedure()
}

~/tmp/govet$ cat proc_amd64.s 
#include "textflag.h"
#include "funcdata.h"
#include "go_asm.h"

TEXT ·procedure(SB), NOSPLIT|NOFRAME, $0-0
    /*
        Commented out garbage

        MOVQ    nonexistingprocedureargument+42(FP), ZMM1
    */
    RET

# this compiles correctly
~/tmp/govet$ go build; echo $?
0

# vet complains
~/tmp/govet$ go vet -asmdecl
# main
./proc_amd64.s:9:1: [amd64] procedure: unknown variable nonexistingprocedureargument

When line 9 is commented with // then go vet does not complain.

@cagedmantis cagedmantis changed the title cmd/vet: -asmdecl scans code in multiline comments cmd/vet: asmdecl flag scans code in multiline comments Mar 6, 2023
@cagedmantis cagedmantis added this to the Backlog milestone Mar 6, 2023
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 6, 2023
@cagedmantis
Copy link
Contributor

Please specify which is line 9.

@cagedmantis
Copy link
Contributor

cc @matloob @timothy-king

@wojciech-sneller
Copy link

Please specify which is line 9.

That's the number from the quoted output:

~/tmp/govet$ go vet -asmdecl
# main
./proc_amd64.s:9:1: [amd64] procedure: unknown variable nonexistingprocedureargument

@wojciech-sneller
Copy link

I looked briefly at x/tools/go/analysis/passes/asmdecl/asmdecl.go, there's a custom, primitive parser. It does not interpret macros, ifdefs, includes, etc.

Example of an other problem:

#define ARG_X_OFS 12345 // silly offset
...
MOVQ x+ARG_X_OFS(FP), AX

Go vet won't complain.

asmdecl has to use the cmd/asm lexer (src/cmd/asm/internal/lex/). Fixing anything in the current parser is possible but IMO makes no sense.

@WojciechMula
Copy link
Author

I was thinking about that issue and the conclusion is: this behaviour should be only documented. go vet has to be fast and pulling a fully-fledged parser only to point out issues in the functionality used by a few people makes no sense.

@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) 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

4 participants