compiler warning in bit_reader.h: use of logical '||' with constant operand #90

Closed
opened 2026-01-29 20:32:42 +00:00 by claunia · 10 comments
Owner

Originally created by @fred-wang on GitHub (Feb 10, 2016).

Brotli fails to build in Gecko when "-Werror,-Wconstant-logical-operand" is enabled:

5:22.18 /home/ckerschb/moz/mc-obj-dbg/dist/include/./bit_reader.h:41:22: error: use of logical '||' with constant operand [-Werror,-Wconstant-logical-operand]
5:22.18 if (IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
5:22.18 ^ ~~~~~~~~~~~~~~~
5:22.18 /home/ckerschb/moz/mc-obj-dbg/dist/include/./bit_reader.h:41:22: note: use '|' for a bitwise operation
5:22.18 if (IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
5:22.18 ^~
5:22.18 |
5:22.18 1 error generated.

See https://bugzilla.mozilla.org/show_bug.cgi?id=1247301

Originally created by @fred-wang on GitHub (Feb 10, 2016). Brotli fails to build in Gecko when "-Werror,-Wconstant-logical-operand" is enabled: 5:22.18 /home/ckerschb/moz/mc-obj-dbg/dist/include/./bit_reader.h:41:22: error: use of logical '||' with constant operand [-Werror,-Wconstant-logical-operand] 5:22.18 if (IS_CONSTANT(n) || BROTLI_HAS_UBFX) { 5:22.18 ^ ~~~~~~~~~~~~~~~ 5:22.18 /home/ckerschb/moz/mc-obj-dbg/dist/include/./bit_reader.h:41:22: note: use '|' for a bitwise operation 5:22.18 if (IS_CONSTANT(n) || BROTLI_HAS_UBFX) { 5:22.18 ^~ 5:22.18 | 5:22.18 1 error generated. See https://bugzilla.mozilla.org/show_bug.cgi?id=1247301
Author
Owner

@fred-wang commented on GitHub (Feb 13, 2016):

I did not try it, but from http://stackoverflow.com/a/32756885 one workaround might be to add a cast to an int in the definitions of BROTLI_HAS_UBFX and IS_CONSTANT(x)

@fred-wang commented on GitHub (Feb 13, 2016): I did not try it, but from http://stackoverflow.com/a/32756885 one workaround might be to add a cast to an int in the definitions of BROTLI_HAS_UBFX and IS_CONSTANT(x)
Author
Owner

@eustas commented on GitHub (Feb 18, 2016):

Hello.
Thank you for the report and sorry for the late response.
I'm going to fix it soon, but first I need to reproduce it. Unfortunately, clang-3.6 does not see this problem...

@eustas commented on GitHub (Feb 18, 2016): Hello. Thank you for the report and sorry for the late response. I'm going to fix it soon, but first I need to reproduce it. Unfortunately, clang-3.6 does not see this problem...
Author
Owner

@fred-wang commented on GitHub (Feb 22, 2016):

This appears in Mozilla MacOSX buildbot (search constant-logical-operand in the raw logs). I tried casting to an (int) but that does not help: https://treeherder.mozilla.org/logviewer.html#?job_id=17040941&repo=try

@fred-wang commented on GitHub (Feb 22, 2016): This appears in Mozilla MacOSX buildbot (search constant-logical-operand in the raw logs). I tried casting to an (int) but that does not help: https://treeherder.mozilla.org/logviewer.html#?job_id=17040941&repo=try
Author
Owner

@eustas commented on GitHub (Feb 23, 2016):

Please, could you check if prepending "!!" to IS_CONSTANT and BROTLI_HAS_UBFX helps?
Thank you.

@eustas commented on GitHub (Feb 23, 2016): Please, could you check if prepending "!!" to IS_CONSTANT and BROTLI_HAS_UBFX helps? Thank you.
Author
Owner

@fred-wang commented on GitHub (Feb 23, 2016):

I just pushed https://treeherder.mozilla.org/#/jobs?repo=try&revision=1133d2b81b26 let's see if that changes something (BTW, I can not reproduce the problem on my Linux system either and my gcc does not recognize the constant-logical-operand warning).

@fred-wang commented on GitHub (Feb 23, 2016): I just pushed https://treeherder.mozilla.org/#/jobs?repo=try&revision=1133d2b81b26 let's see if that changes something (BTW, I can not reproduce the problem on my Linux system either and my gcc does not recognize the constant-logical-operand warning).
Author
Owner

@eustas commented on GitHub (Feb 23, 2016):

It seems you've missed
#define IS_CONSTANT(x) (!!__builtin_constant_p(x))

@eustas commented on GitHub (Feb 23, 2016): It seems you've missed `#define IS_CONSTANT(x) (!!__builtin_constant_p(x))`
Author
Owner

@fred-wang commented on GitHub (Feb 23, 2016):

OK, the double exclamation mark trick seems to work:

https://treeherder.mozilla.org/#/jobs?repo=try&revision=592ee4d1c523&selectedJob=17086321
http://archive.mozilla.org/pub/firefox/try-builds/fred.wang@free.fr-592ee4d1c5238f8990b3deffc3cd42b6ff5fba1f/try-macosx64/try-macosx64-bm83-try1-build15516.txt.gz

The previous changeset was:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=2eb88e7da740
http://archive.mozilla.org/pub/firefox/try-builds/jnicol@mozilla.com-2eb88e7da740319ac602ca3f0502cea59a498d3a/try-macosx64/try-macosx64-bm87-try1-build13456.txt.gz

03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/modules/woff2/Unified_cpp_modules_woff20.cpp:29:
03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/modules/woff2/src/woff2_dec.cc:39:
03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./decode.h:12:
03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./state.h:12:
03:55:15 INFO - Warning: -Wconstant-logical-operand in /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/bit_reader.h: use of logical '||' with constant operand
03:55:15 INFO - /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./bit_reader.h:41:31: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
03:55:15 INFO - if (__builtin_constant_p(n) || 0) {
03:55:15 INFO - ^ ~
03:55:15 INFO - /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./bit_reader.h:41:31: note: use '|' for a bitwise operation
03:55:15 INFO - if (__builtin_constant_p(n) || 0) {
03:55:15 INFO - ^~
03:55:15 INFO - |
03:55:15 INFO - 1 warning generated.
03:55:15 INFO - libwoff2.a.desc
03:55:15 INFO - rm -f libwoff2.a
03:55:15 INFO - /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/_virtualenv/bin/python /builds/slave/try-m64-0000000000000000000000/build/src/config/expandlibs_gen.py -o libwoff2.a.desc Unified_cpp_modules_woff20.o

@fred-wang commented on GitHub (Feb 23, 2016): OK, the double exclamation mark trick seems to work: https://treeherder.mozilla.org/#/jobs?repo=try&revision=592ee4d1c523&selectedJob=17086321 http://archive.mozilla.org/pub/firefox/try-builds/fred.wang@free.fr-592ee4d1c5238f8990b3deffc3cd42b6ff5fba1f/try-macosx64/try-macosx64-bm83-try1-build15516.txt.gz The previous changeset was: https://treeherder.mozilla.org/#/jobs?repo=try&revision=2eb88e7da740 http://archive.mozilla.org/pub/firefox/try-builds/jnicol@mozilla.com-2eb88e7da740319ac602ca3f0502cea59a498d3a/try-macosx64/try-macosx64-bm87-try1-build13456.txt.gz 03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/modules/woff2/Unified_cpp_modules_woff20.cpp:29: 03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/modules/woff2/src/woff2_dec.cc:39: 03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./decode.h:12: 03:55:15 INFO - In file included from /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./state.h:12: 03:55:15 INFO - Warning: -Wconstant-logical-operand in /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/bit_reader.h: use of logical '||' with constant operand 03:55:15 INFO - /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./bit_reader.h:41:31: warning: use of logical '||' with constant operand [-Wconstant-logical-operand] 03:55:15 INFO - if (__builtin_constant_p(n) || 0) { 03:55:15 INFO - ^ ~ 03:55:15 INFO - /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/dist/include/./bit_reader.h:41:31: note: use '|' for a bitwise operation 03:55:15 INFO - if (__builtin_constant_p(n) || 0) { 03:55:15 INFO - ^~ 03:55:15 INFO - | 03:55:15 INFO - 1 warning generated. 03:55:15 INFO - libwoff2.a.desc 03:55:15 INFO - rm -f libwoff2.a 03:55:15 INFO - /builds/slave/try-m64-0000000000000000000000/build/src/obj-firefox/x86_64/_virtualenv/bin/python /builds/slave/try-m64-0000000000000000000000/build/src/config/expandlibs_gen.py -o libwoff2.a.desc Unified_cpp_modules_woff20.o
Author
Owner

@fred-wang commented on GitHub (Feb 23, 2016):

It seems you've missed
#define IS_CONSTANT(x) (!!__builtin_constant_p(x))

The constant-logical-operand warning only seems to complain about constant operands, but I guess it's safe to do that too...

@fred-wang commented on GitHub (Feb 23, 2016): > It seems you've missed > #define IS_CONSTANT(x) (!!__builtin_constant_p(x)) The constant-logical-operand warning only seems to complain about constant operands, but I guess it's safe to do that too...
Author
Owner

@eustas commented on GitHub (Feb 24, 2016):

Okay. Thank you. I'm going to make a fix soon.

@eustas commented on GitHub (Feb 24, 2016): Okay. Thank you. I'm going to make a fix soon.
Author
Owner

@fred-wang commented on GitHub (Feb 25, 2016):

OK, I just opened #322

@fred-wang commented on GitHub (Feb 25, 2016): OK, I just opened #322
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#90