Skip to content

nlreturn false positives when using cgo #5714

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

Closed
6 of 7 tasks
emm1R opened this issue Apr 10, 2025 · 3 comments
Closed
6 of 7 tasks

nlreturn false positives when using cgo #5714

emm1R opened this issue Apr 10, 2025 · 3 comments
Labels
area: cgo Related to CGO or line directives bug Something isn't working

Comments

@emm1R
Copy link

emm1R commented Apr 10, 2025

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

How did you install golangci-lint?

Brew

Description of the problem

When using cgo, I receive false positives from nlreturn. It is saying return with no blank line before for lines with defer or return when these lines call C functions. Adding a newline does not remove the issue. The problem with return lines does not happen always, and I was unable to replicate it in the example.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 2.0.2 built with go1.24.1 from 2b224c2c on 2025-03-25T21:36:18Z

Configuration

-E nlreturn

Go environment

$ go version && go env
go version go1.24.0 darwin/arm64
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/emrehn/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/emrehn/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/50/f2qw2dqn6dv5hsq9mfk7_zlw0000gp/T/go-build117157792=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/emrehn/Documents/git/test-nlreturn/go.mod'
GOMODCACHE='/Users/emrehn/go/1.24.0/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/emrehn/go/1.24.0'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/emrehn/.goenv/versions/1.24.0'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/emrehn/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/emrehn/.goenv/versions/1.24.0/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO golangci-lint has version 2.0.2 built with go1.24.1 from 2b224c2c on 2025-03-25T21:36:18Z 
INFO [config_reader] Config search paths: [./ /Users/emrehn/Documents/git/test-nlreturn /Users/emrehn/Documents/git /Users/emrehn/Documents /Users/emrehn /Users /] 
INFO maxprocs: Leaving GOMAXPROCS=8: CPU quota undefined 
INFO [goenv] Read go env for 10.982667ms: map[string]string{"GOCACHE":"/Users/emrehn/Library/Caches/go-build", "GOROOT":"/Users/emrehn/.goenv/versions/1.24.0"} 
INFO [lintersdb] Active 5 linters: [errcheck govet ineffassign staticcheck unused] 
INFO [loader] Go packages loading at mode 8767 (imports|compiled_files|deps|exports_file|files|name|types_sizes) took 267.376375ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 1.793375ms 
INFO [linters_context/goanalysis] analyzers took 878.248092ms with top 10 stages: buildir: 585.437248ms, fact_deprecated: 60.726375ms, printf: 47.304998ms, ctrlflow: 38.757214ms, SA5012: 32.662958ms, fact_purity: 28.669753ms, nilness: 26.778172ms, inspect: 25.80021ms, typedness: 25.015751ms, tokenfileanalyzer: 1.35475ms 
INFO [runner] processing took 1.33µs with stages: max_same_issues: 250ns, exclusion_rules: 208ns, exclusion_paths: 208ns, path_absoluter: 167ns, path_shortener: 166ns, nolint_filter: 83ns, path_relativity: 42ns, source_code: 42ns, filename_unadjuster: 41ns, max_from_linter: 41ns, generated_file_filter: 41ns, invalid_issue: 41ns, fixer: 0s, path_prettifier: 0s, sort_results: 0s, diff: 0s, severity-rules: 0s, cgo: 0s, max_per_file_from_linter: 0s, uniq_by_line: 0s 
INFO [runner] linters took 565.383125ms with stages: goanalysis_metalinter: 565.337042ms 
0 issues.
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 10 samples, avg is 131.5MB, max is 243.9MB 
INFO Execution took 846.381667ms  

A minimal reproducible example or link to a public repository

package main

/*
#include <stdlib.h>
*/
import "C"
import (
        "fmt"
        "unsafe"
)

func testFunc(str string) {
        cstr := C.CString(str)
        defer C.free(unsafe.Pointer(cstr))

        fmt.Printf("%v\n", C.GoString(cstr))
}

func main() {
        testFunc("hello world")
}

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@emm1R emm1R added the bug Something isn't working label Apr 10, 2025
Copy link

boring-cyborg bot commented Apr 10, 2025

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez ldez added the area: cgo Related to CGO or line directives label Apr 10, 2025
@ldez
Copy link
Member

ldez commented Apr 10, 2025

Thank you for the report.

Closed in favor of #5235

@ldez ldez closed this as completed Apr 10, 2025
@bombsimon
Copy link
Member

Also worth mentioning that this is an upstream issue: ssgreg/nlreturn#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cgo Related to CGO or line directives bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants