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

Unkown warning option '-Wunused-but-set-parameter' when using clang #3622

Closed
RenatoUtsch opened this issue Aug 25, 2017 · 14 comments
Closed

Comments

@RenatoUtsch
Copy link

RenatoUtsch commented Aug 25, 2017

All my C++ projects started throwing the following two warning lines after I updated Bazel to the latest version:

warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-free-nonheap-object'; did you mean '-Wno-sequence-point'? [-Wunknown-warning-option]

These warnings are extremely irritating, because they appear for all source files and clutter the terminal. Even more, as I use -Werror, these warnings break my build.

This happens with every C++ library/binary I try to build. For example, upon inspecting the build commands of one of these libraries with the -s option, you can see that Bazel adds these two warning options when it shouldn't:

>>>>> # //herakles/vulkan:utils [action 'Compiling herakles/vulkan/utils.cpp']                           
(cd /home/renato/.cache/bazel/_bazel_renato/a009e38a5efb52dabc3a2546ba473f66/execroot/com_github_renatoutsch_herakles && \
  exec env - \            
    PATH=/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/renato/go/bin:/home/renato/.npm-global/bin:/home/renato/go/bin:/home/renato/.npm-global/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/renato/go/bin:/home/renato/.npm-global/bin \
    PWD=/proc/self/cwd \  
  /usr/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/local-fastbuild/bin/herakles/vulkan/_objs/utils/herakles/vulkan/utils.pic.d '-frandom-seed=bazel-out/local-fastbuild/bin/herakles/vulkan/_objs/utils/herakles/vulkan/utils.pic.o' -fPIC -iquote . -iquote bazel-out/local-fastbuild/genfiles -iquote external/glog -iquote bazel-out/local-fastbuild/genfiles/external/glog -iquote external/bazel_tools -iquote bazel-out/local-fastbuild/genfiles/external/bazel_tools -isystem external/glog -isystem bazel-out/local-fastbuild/genfiles/external/glog -isystem external/bazel_tools/tools/cpp/gcc3 -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c herakles/vulkan/utils.cpp -o bazel-out/local-fastbuild/bin/herakles/vulkan/_objs/utils/herakles/vulkan/utils.pic.o)
INFO: From Compiling herakles/vulkan/utils.cpp:     
warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-free-nonheap-object'; did you mean '-Wno-sequence-point'? [-Wunknown-warning-option]
2 warnings generated.

Just to be clear, I am not adding these two flags to the command line.

I'm using clang in ArchLinux, with bazel release 0.5.3.- (@non-git). I installed Bazel using pacman, so I don't know why it shows (@non-git).

It seems some people on Tensorflow are also having the same problem:
tensorflow/tensorflow#12123

@RenatoUtsch
Copy link
Author

RenatoUtsch commented Aug 26, 2017

Upon digging some more, this in fact does not seem to be related to Bazel's version. I discovered what is triggering these warnings.

It seems that these warnings appear if the CC environment variable is set to clang. If I change the CC environment variable to gcc, the warnings disappear.

Also, while changing the CC environment variable seems to reproduce this bug on Linux, I can't reproduce it on Mac OS.

@luchensk
Copy link

Thanks @RenatoUtsch .

As you said, it is not working by changing the CC environment to gcc on MAC OS, and these are some env info on my MAC, as below:

$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.4
BuildVersion: 16E195

$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ clang -v
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ bazel version
Build label: 0.5.3-homebrew
Build target: bazel-out/darwin_x86_64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Jul 27 19:30:37 2017 (1501183837)
Build timestamp: 1501183837
Build timestamp as int: 1501183837

@gunan
Copy link

gunan commented Aug 28, 2017

I don't think we do any autoconf with cc. We just check operating system and set flags.
@damienmg to confirm if we have a mechanism to pick compilers in an OS.

@luchensk
Copy link

Thanks @gunan . For the detail of the error on TF, I post here just in case you need it:

ERROR: /private/var/tmp/_bazel_sunkai/f32adcfaaeaeed39ed3812ab214ba306/external/boringssl/BUILD:131:1: C++ compilation of rule '@boringssl//:ssl' failed (Exit 1): cc_wrapper.sh failed: error executing command (exec env - \ PATH=/Users/sunkai/work/workspace/project/tf-env/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home:/Users/sunkai/ali-dev-env/apache-maven-3.5.0/bin \ PWD=/proc/self/cwd \ PYTHON_BIN_PATH=/Users/sunkai/work/workspace/project/tf-env/bin/python \ PYTHON_LIB_PATH=/Users/sunkai/work/workspace/project/tf-env/lib/python2.7/site-packages \ TF_NEED_CUDA=0 \ TF_NEED_OPENCL=0 \ TMPDIR=/var/folders/sn/j9d72mw55fv9wqd3sn55sn8c0000gn/T/ \ external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-march=native' -MD -MF bazel-out/local-opt/bin/external/boringssl/_objs/ssl/external/boringssl/src/ssl/s3_pkt.pic.d -fPIC -iquote external/boringssl -iquote bazel-out/local-opt/genfiles/external/boringssl -iquote external/bazel_tools -iquote bazel-out/local-opt/genfiles/external/bazel_tools -isystem external/boringssl/src/include -isystem bazel-out/local-opt/genfiles/external/boringssl/src/include -isystem external/bazel_tools/tools/cpp/gcc3 -Wa,--noexecstack '-D_XOPEN_SOURCE=700' -Wall -Werror '-Wformat=2' -Wsign-compare -Wmissing-field-initializers -Wwrite-strings -Wshadow -fno-common '-std=c11' -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/boringssl/src/ssl/s3_pkt.c -o bazel-out/local-opt/bin/external/boringssl/_objs/ssl/external/boringssl/src/ssl/s3_pkt.pic.o). error: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Werror,-Wunknown-warning-option] error: unknown warning option '-Wno-free-nonheap-object'; did you mean '-Wno-sequence-point'? [-Werror,-Wunknown-warning-option] Target //tensorflow/tools/pip_package:build_pip_package failed to build

@luchensk
Copy link

For the error on TF, refer to tensorflow/tensorflow#12123 and it works now, thanks.

@damienmg
Copy link
Contributor

/cc @mhlopko

We do auto config in Bazel itself.

@RenatoUtsch
Copy link
Author

RenatoUtsch commented Aug 28, 2017 via email

@hlopko
Copy link
Member

hlopko commented Aug 28, 2017

We do have an ability to specify/detect which compiler should be used by bazel. It all happens in
https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl.

This is where we check for flags in question:
https://github.com/bazelbuild/bazel/blob/master/tools/cpp/unix_cc_configure.bzl#L229

So it's running something like:

clang -Wunused-but-set-parameter -o /dev/null -c empty.cc

and searching for -Wunused-but-set-parameter in stderr. Any idea what is wrong there? My clang returns:

warning: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Wunknown-warning-option]
1 warning generated.

@RenatoUtsch do I understand correctly that this was working correctly with older bazel? Or with the upgrade you also changed the value of CC env var?

@luchensk CC fix doesn't work for you because your gcc is actually clang.

@luchensk
Copy link

@mhlopko got it, thanks:), let's wait for the result from @RenatoUtsch with update to 0.5.4.

@pcj
Copy link
Member

pcj commented Sep 1, 2017

This is also breaks rules_protobuf with bazel 0.5.3 on darwin due to boringssl compilation failure.

pcj:~/github/rules_protobuf*master$ bazel build @boringssl//:ssl 
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_pcj/63330772b4917b139280caef8bb81867/external/boringssl/BUILD:92:1: C++ compilation of rule '@boringssl//:crypto' failed (Exit 1).
error: unknown warning option '-Wunused-but-set-parameter'; did you mean '-Wunused-parameter'? [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wno-free-nonheap-object'; did you mean '-Wno-sequence-point'? [-Werror,-Wunknown-warning-option]
Target @boringssl//:ssl failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 26.306s, Critical Path: 0.18s
pcj:~/github/rules_protobuf*master$ bazel version
Build label: 0.5.3
Build target: bazel-out/darwin_x86_64-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jul 28 08:34:35 2017 (1501230875)
Build timestamp: 1501230875
Build timestamp as int: 1501230875

Issue is resolved on 0.5.4:

pcj:~/github/rules_protobuf*master$ bazel build @boringssl//:ssl
INFO: Found 1 target...
Target @boringssl//:ssl up-to-date:
  bazel-bin/external/boringssl/libssl.a
  bazel-bin/external/boringssl/libssl.so
INFO: Elapsed time: 40.195s, Critical Path: 1.59s
pcj:~/github/rules_protobuf*master$ bazel version
Build label: 0.5.4
Build target: bazel-out/darwin_x86_64-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Aug 25 09:57:39 2017 (1503655059)
Build timestamp: 1503655059
Build timestamp as int: 1503655059

@RenatoUtsch
Copy link
Author

RenatoUtsch commented Sep 1, 2017

I updated to 0.5.4 and the issue is resolved. This was an issue on 0.5.3 only.

I'll close the issue as it was resolved already.

@hlopko
Copy link
Member

hlopko commented Sep 4, 2017

Hi @pcj, can you also verify it works with 0.5.4 please?

@RenatoUtsch
Copy link
Author

He edited his last comment to say that it was resolved with 0.5.4.

@hlopko
Copy link
Member

hlopko commented Sep 4, 2017

Oh I haven't noticed. Thanks. So this really is resolved. Thanks everybody!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants