goccy / go-graphviz

Go bindings for Graphviz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build warnings of [-Wsingle-bit-bitfield-constant-conversion] from outdated GraphViz library

thomasfleming-cs opened this issue · comments

Environment details

Go version

$ go version
go version go1.21.1 darwin/arm64

C Compiler

$ go env
...
CC='clang'
...

$ clang --version
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.2.0
Thread model: posix
...

Issue

When building the example code in the repository's readme with go build, I see the following compiler warnings from clang:

# github.com/goccy/go-graphviz/internal/ccall
In file included from common.c:5:
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:165:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2540:24: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2596:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2602:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2612:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2623:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2628:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2641:28: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2650:33: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2659:32: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../go/modcache/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2668:32: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]

Note that this is a separate issue from #72 and is not fixed by #77.

These come from the bundled GraphViz library assigning a literal 1 to signed int bitfields of an obj_state_t. This issue was resolved in GraphViz 3.0.0 released on 2022-02-26. The specific commit with the fix is 96f9d101, which simply changes the relevant bitfields to unsigned ints. These bitfields are present in go-graphviz here:

int explicit_tooltip:1;
int explicit_tailtooltip:1;
int explicit_headtooltip:1;
int explicit_labeltooltip:1;
int explicit_tailtarget:1;
int explicit_headtarget:1;
int explicit_edgetarget:1;
int explicit_tailurl:1;
int explicit_headurl:1;
int labeledgealigned:1;

This issue can be resolved extremely easily by replacing the int keyword with unsigned (alias for unsigned int) in the above code, just as the GraphViz developers did. However, I would like to push for #42 to be finished and the bundled libraries (including GraphViz and Expat) to be updated to more recent versions. Updating the bundled dependencies would close out several other issues in this repository, like #47. More pressingly, bundling outdated libraries poses a security risk, as evidenced by the Expat CVEs mentioned in #76.

Please let me know if you would like me to submit a PR for the specific issue of the bitfield warnings. In the meantime, can you provide a timeline on when the bundled libraries might be able to be updated? Thank you.

commented

I am also having the same bug on latest master and latest tagged.

clang --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin


go install github.com/goccy/go-graphviz/cmd/dot@master
go: downloading github.com/goccy/go-graphviz v0.1.3-0.20240305010347-606fdf55b06d
# github.com/goccy/go-graphviz/internal/ccall
In file included from common.c:5:
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:165:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2540:24: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2596:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2602:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2612:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2623:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2628:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2641:28: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2650:33: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2659:32: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.3-0.20240305010347-606fdf55b06d/internal/ccall/common/emit.c:2668:32: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]



go install github.com/goccy/go-graphviz/cmd/dot@v0.1.2
# github.com/goccy/go-graphviz/internal/ccall
In file included from common.c:5:
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:165:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2540:24: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2596:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2602:35: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2612:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2623:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2628:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2641:28: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2650:33: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2659:32: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
../../../../../../../../pkg/mod/github.com/goccy/go-graphviz@v0.1.2/internal/ccall/common/emit.c:2668:32: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]