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/go: error: pointer is missing a nullability type specifier when building on catalina #35247

Closed
Tochemey opened this issue Oct 30, 2019 · 22 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin release-blocker
Milestone

Comments

@Tochemey
Copy link

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

$ go version
go version go1.13.3 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/arsenegandote/Library/Caches/go-build"
GOENV="/Users/arsenegandote/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/arsenegandote/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_9/v2g8jyjj051bj38hln17lchw0000gn/T/go-build584306134=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go test -mod=vendor

What did you expect to see?

At least the test should run

What did you see instead?

runtime/cgo

In file included from _cgo_export.c:3:
/usr/local/include/stdlib.h:134:25: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:134:25: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:134:25: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:135:22: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:135:22: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:135:22: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:136:23: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:136:23: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:136:23: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:139:20: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:139:20: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:139:20: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:141:26: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:141:26: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:141:26: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:141:45: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:141:45: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:141:45: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:142:59: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:142:59: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:142:59: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:142:73: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:142:73: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:142:73: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:141:6: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:141:6: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:141:6: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:147:25: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:147:25: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:147:25: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:147:6: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:147:6: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:147:6: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:156:23: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:156:23: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:156:23: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:157:26: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:157:26: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:157:26: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:157:52: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:157:52: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:157:52: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:158:21: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:158:21: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:158:21: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:158:46: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:158:46: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:158:46: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:160:18: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:160:18: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:160:18: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:161:43: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:161:43: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:161:43: note: insert '_Nonnull' if the pointer should never be null
/usr/local/include/stdlib.h:161:57: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
/usr/local/include/stdlib.h:161:57: note: insert '_Nullable' if the pointer may be null
/usr/local/include/stdlib.h:161:57: note: insert '_Nonnull' if the pointer should never be null
fatal error: too many errors emitted, stopping now [-ferror-limit=]

Compilation finished with exit code 2

@ianlancetaylor
Copy link
Contributor

Has clang really decided to enable the -Wnullability-completeness warning by default, as suggested by https://bcain-llvm.readthedocs.io/projects/clang/en/latest/DiagnosticsReference/#wnullability-completeness ? That seems designed to break all existing code. I must be missing something.

@ianlancetaylor
Copy link
Contributor

Note that these warnings are for /usr/local/include/stdlib.h, which does not come from Go. Is that the version of stdlib.h that corresponds to the C compiler that you are using?

@andybons andybons added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 30, 2019
@andybons andybons added this to the Unplanned milestone Oct 30, 2019
@andybons andybons changed the title go build issue on macos catalina cmd/go: build issue on macos catalina Oct 30, 2019
@Tochemey
Copy link
Author

@ianlancetaylor I cannot really tell. I just did an upgrade to catalina and installed golang. So when I try to build I got the error. During the installation I did not get any errors that could have given a hint.

@ianlancetaylor
Copy link
Contributor

Unless someone else is seeing this problem on catalina, I suspect this is a problem with the installation on your system.

@ianlancetaylor
Copy link
Contributor

Sorry, I mean a problem with the XCode installation. I don't see a reason to think that there is anything wrong with the Go installation.

@42yeah
Copy link

42yeah commented Oct 31, 2019

Had the same problem. Upgraded to catalina and this appears:

# runtime/cgo
In file included from _cgo_export.c:3:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:134:25: error: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Werror,-Wnullability-completeness]
...

Also tried using clang to compile some random source including stdlib.h, and it did it gave out bunches of warnings almost identical to the above, however those weren't error, only warnings:

❯ clang a.c
In file included from a.c:1:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:134:25: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
double   atof(const char *);
...

@dust347
Copy link

dust347 commented Oct 31, 2019

I also have same problem after upgrade to catalina

export CGO_CPPFLAGS="-Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined"

Maybe it can be solved

@ALTree ALTree changed the title cmd/go: build issue on macos catalina cmd/go: error: pointer is missing a nullability type specifier when building on catalina Oct 31, 2019
@ianlancetaylor
Copy link
Contributor

I don't understand how XCode could possibly be shipping a <stdlib.h> that cannot be compiled without warnings in the default compiler setting. Can somebody investigate that? What happens if you simply compile the C program

#include <stdlib.h>

? Do you get warnings?

@yiyanwannian
Copy link

Encounter same issue

@ianlancetaylor
Copy link
Contributor

@yiyanwannian Please see my question in #35247 (comment) which has not yet been answered. Thanks.

@42yeah
Copy link

42yeah commented Nov 5, 2019

@ianlancetaylor Please see my comment above. And here's the content of a.c:

#include <stdlib.h>

int main() {

  return 0;
}

It has the same problem when being compiled, however those were only warnings. When in cgo, those became errors.

@ianlancetaylor
Copy link
Contributor

I'm sorry, somehow I missed that comment.

If clang is emitting a lot of warnings for code that simply includes <stdlib.h>, I can't help but feel that that is a problem with the installation.

I see this issue raised for C code on Stack Overflow at https://stackoverflow.com/questions/58429844/c-multiple-warnings-pointer-is-missing-a-nullability-type-specifier-when-com .

This just seems to me like something that Apple has to fix.

In the meantime see if https://golang.org/cl/205457 fixes the problems.

@ianlancetaylor ianlancetaylor added release-blocker and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Nov 5, 2019
@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Go1.14 Nov 5, 2019
@bradfitz
Copy link
Contributor

bradfitz commented Nov 5, 2019

A Catalina builder would've caught this (#34748).

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/205457 mentions this issue: runtime/cgo: add -Wno-nullability-completeness on Darwin

@daravi
Copy link

daravi commented Jan 30, 2020

If clang is emitting a lot of warnings for code that simply includes <stdlib.h>, I can't help but feel that that is a problem with the installation.

For what it's worth I don't see the issue with XCode 11.3 on Mojave using system's clang, but do get it if I use my clang built from source.

@bigemon
Copy link

bigemon commented Feb 5, 2020

I also have same problem after upgrade to catalina

export CGO_CPPFLAGS="-Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined"

Maybe it can be solved

you saved my day, thanks :)

@felixge
Copy link
Contributor

felixge commented Feb 20, 2020

I just upgraded to Catalina and also had issues with clang throwing warnings.

Turns out this was caused by having installed clang via homebrew. brew remove llvm fixed the issue.

So perhaps https://go-review.googlesource.com/c/go/+/205457/ is only needed to support users who have installed their own version of clang?

@matiasinsaurralde
Copy link

I'm facing the same issue 😞

@davecheney
Copy link
Contributor

@matiasinsaurralde this issue is closed. If the problem occurs for you with the latest version of Go please open a new issue including all the information someone who does not have access to your environment will need to reproduce the problem.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/368634 mentions this issue: runtime/cgo: remove stdlib.h warning workaround on darwin

@bcmills
Copy link
Contributor

bcmills commented Dec 2, 2021

The Clang documentation for -Wnullability-completeness gives its error text but not its actual semantics.

From the doc comment for the actual implementation in the compiler, the warning enabled by the flag actually:

Complains about missing nullability if the file … has other uses of nullability (either the keywords or the assume_nonnull pragma).

So this is indeed a configuration problem, caused by mixing a clang with strict nullability checks with a stdlib.h (and its transitively-included headers) that contains a mix of annotated and unannotated pointers.

That seems to jibe with the theory in #35247 (comment) that this may be caused by mixing a Homebrew clang with an XCode stdlib.h, or perhaps by mixing Homebrew and XCode headers for dependencies of stdlib.h.

@bcmills
Copy link
Contributor

bcmills commented Dec 2, 2021

As as interesting data point, CL 368634 removes the -Wno-nullability-completeness workaround and passes on all of the Go project's Cgo-enabled macOS builders.

gopherbot pushed a commit that referenced this issue Apr 22, 2022
CL 205457 added the flag -Wno-nullability-completeness to work
around a user-reported build breakage on macOS Catalina.

However, according to
https://golang.org/issue/35247#issuecomment-589115489 the root cause
of the breakage may be a toolchain misconfiguration on the host
(perhaps compiling the XCode stdlib using a Homebrew build of the
"clang" compiler?).

Adding an obscure warning flag to enable building stdlib.h with an
otherwise-broken toolchain seems clearly inappropriate to me.
If need be we can instead provide guidance to users on how to unbreak
their toolchain.

Updates #35247
Fixes #49913

Change-Id: I84def34e101bed7911d8d78a991a29095b8791fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/368634
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin release-blocker
Projects
None yet
Development

No branches or pull requests