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/cgo: Wrong types in compiler errors with clang 14 #53013

Closed
dmgk opened this issue May 20, 2022 · 2 comments
Closed

cmd/cgo: Wrong types in compiler errors with clang 14 #53013

dmgk opened this issue May 20, 2022 · 2 comments
Labels
NeedsFix
Milestone

Comments

@dmgk
Copy link
Member

@dmgk dmgk commented May 20, 2022

When compiling this code on FreeBSD 14-CURRENT with clang 14, go emits error messages with invalid types:

package main

import "C"

func main() {
        var _ C.ulong = "ul"
        var _ C.ulonglong = "ull"
}
$ go build example.go
# command-line-arguments
./example.go:6:18: cannot use "ul" (untyped string constant) as _Ctype_unsignedlong value in variable declaration
./example.go:7:22: cannot use "ull" (untyped string constant) as _Ctype_unsignedlonglong value in variable declaration

cgo tests also currently are failing:

##### Test execution environment.
# GOARCH: amd64
# CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
# GOOS: freebsd
# OS Version: FreeBSD 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n255691-41ce5498f8e: Wed May 18 10:46:22 -05 2022     root@xombo.locald
omain:/usr/obj/usr/src/amd64.amd64/sys/XOMBO  amd64
...
##### ../misc/cgo/errors
--- FAIL: TestReportsTypeErrors (0.38s)
    --- FAIL: TestReportsTypeErrors/err2.go (0.32s)
        errors_test.go:76: found match for `err2\.go:37:`: "testdata/err2.go:37:11: cannot use s (variable of type string) as type C.unsignedlong in argument to (C._CMalloc)"
        errors_test.go:76: found match for `err2\.go:40:`: "testdata/err2.go:40:11: cannot use x (variable of type *C.struct_bar) as type *C.struct_foo in assignment"
        errors_test.go:76: found match for `:44:.*C\.ushort`: "testdata/err2.go:44:7: cannot use int(0) (constant 0 of type int) as type C.ushort in assignment"
        errors_test.go:76: found match for `err2\.go:47:`: "testdata/err2.go:47:6: not enough arguments in call to (C.fopen)"
        errors_test.go:76: found match for `:51:.*C\.int`: "testdata/err2.go:51:27: cannot use x2 (variable of type rune) as type C.int in argument to (C.transform)"
        errors_test.go:76: found match for `:56:.*C\.uchar`: "testdata/err2.go:56:23: cannot use \"uc\" (untyped string constant) as C.uchar value in variable declaration"
        errors_test.go:76: found match for `:57:.*C\.schar`: "testdata/err2.go:57:23: cannot use \"sc\" (untyped string constant) as C.schar value in variable declaration"
        errors_test.go:76: found match for `:58:.*C\.ushort`: "testdata/err2.go:58:23: cannot use \"us\" (untyped string constant) as C.ushort value in variable declaration"
        errors_test.go:76: found match for `:59:.*C\.uint`: "testdata/err2.go:59:23: cannot use \"ui\" (untyped string constant) as C.uint value in variable declaration"
        errors_test.go:82: expected error output to contain `:60:.*C\.ulong`
        errors_test.go:76: found match for `:61:.*C\.longlong`: "testdata/err2.go:61:23: cannot use \"ll\" (untyped string constant) as C.longlong value in variable declaration"
        errors_test.go:82: expected error output to contain `:62:.*C\.ulonglong`
        errors_test.go:76: found match for `:63:.*C\.complexfloat`: "testdata/err2.go:63:23: cannot use \"cf\" (untyped string constant) as C.complexfloat value in variable declaration"
        errors_test.go:76: found match for `:64:.*C\.complexdouble`: "testdata/err2.go:64:23: cannot use \"cd\" (untyped string constant) as C.complexdouble value in variable declaration"
        errors_test.go:76: found match for `err2\.go:75:`: "testdata/err2.go:75:44: cannot use _cgo0 (variable of type **C.void) as type *unsafe.Pointer in argument to C.F"
        errors_test.go:76: found match for `err2\.go:82:`: "testdata/err2.go:82:12: not enough arguments in call to (C.fvi)"
        errors_test.go:76: found match for `err2\.go:89:`: "testdata/err2.go:89:24: cannot use _cgo0 (variable of type *x) as type **C.int in argument to C.fppi"
        errors_test.go:76: found match for `:98:.*\b(10|14)\b`: "testdata/err2.go:98:10: cannot use (*C.i) + 1 (value of type C.int) as type int in return statement"
        errors_test.go:76: found match for `:105:.*\b(7|8)\b`: "testdata/err2.go:105:8: cannot use i (variable of type int) as type C.int in argument to (C.fi)"
        errors_test.go:76: found match for `err2\.go:108:`: "testdata/err2.go:108:2: cannot assign to (_Cgo_ptr(_Cfpvar_fp_fi)) (value of type unsafe.Pointer)"
        errors_test.go:87: actual output:
            # command-line-arguments
            testdata/err2.go:37:11: cannot use s (variable of type string) as type C.unsignedlong in argument to (C._CMalloc)
            testdata/err2.go:40:11: cannot use x (variable of type *C.struct_bar) as type *C.struct_foo in assignment
            testdata/err2.go:44:7: cannot use int(0) (constant 0 of type int) as type C.ushort in assignment
            testdata/err2.go:47:6: not enough arguments in call to (C.fopen)
                have ()
                want (*C.char, *C.char)
            testdata/err2.go:51:27: cannot use x2 (variable of type rune) as type C.int in argument to (C.transform)
            testdata/err2.go:51:15: cannot use (C.transform)(x2) (value of type C.int) as type rune in variable declaration
            testdata/err2.go:56:23: cannot use "uc" (untyped string constant) as C.uchar value in variable declaration
            testdata/err2.go:57:23: cannot use "sc" (untyped string constant) as C.schar value in variable declaration
            testdata/err2.go:58:23: cannot use "us" (untyped string constant) as C.ushort value in variable declaration
            testdata/err2.go:59:23: cannot use "ui" (untyped string constant) as C.uint value in variable declaration
            testdata/err2.go:60:23: cannot use "ul" (untyped string constant) as C.unsignedlong value in variable declaration
            testdata/err2.go:61:23: cannot use "ll" (untyped string constant) as C.longlong value in variable declaration
            testdata/err2.go:62:23: cannot use "ull" (untyped string constant) as C.unsignedlonglong value in variable declaration
            testdata/err2.go:63:23: cannot use "cf" (untyped string constant) as C.complexfloat value in variable declaration
            testdata/err2.go:64:23: cannot use "cd" (untyped string constant) as C.complexdouble value in variable declaration
            testdata/err2.go:75:44: cannot use _cgo0 (variable of type **C.void) as type *unsafe.Pointer in argument to C.F
            testdata/err2.go:82:12: not enough arguments in call to (C.fvi)
                have (number)
                want (unsafe.Pointer, C.int)
            testdata/err2.go:89:24: cannot use _cgo0 (variable of type *x) as type **C.int in argument to C.fppi
            testdata/err2.go:98:10: cannot use (*C.i) + 1 (value of type C.int) as type int in return statement
            testdata/err2.go:105:8: cannot use i (variable of type int) as type C.int in argument to (C.fi)
            testdata/err2.go:108:2: cannot assign to (_Cgo_ptr(_Cfpvar_fp_fi)) (value of type unsafe.Pointer)
FAIL

The above was tested with

$ go version
go version devel go1.19-d8762b2f45 Thu May 19 21:33:15 2022 +0000 freebsd/amd64

$ clang --version
FreeBSD clang version 14.0.3 (https://github.com/llvm/llvm-project.git llvmorg-14.0.3-0-g1f9140064dfb)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin

This issue seems to be similar to #13129 and #13635, CL incoming shortly.

@gopherbot
Copy link

@gopherbot gopherbot commented May 20, 2022

Change https://go.dev/cl/407514 mentions this issue: cmd/cgo: handle Clang 14 DWARF quirks

@mknyszek mknyszek added the NeedsInvestigation label May 20, 2022
@mknyszek mknyszek added this to the Backlog milestone May 20, 2022
@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented May 20, 2022

CC @golang/runtime, maybe @thanm?

@dmitshur dmitshur added NeedsFix and removed NeedsInvestigation labels Jun 9, 2022
@dmitshur dmitshur removed this from the Backlog milestone Jun 9, 2022
@dmitshur dmitshur added this to the Go1.19 milestone Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix
Projects
None yet
Development

No branches or pull requests

4 participants