clang: & precedence

Thomas Klausner wiz at NetBSD.org
Sat Nov 30 09:11:15 UTC 2013


Hi!

NetBSD currently contains in its source tree gmp-5.1.3 (for compiling
gcc, also included) and clang (as alternative compiler). Either gcc or
clang can be chosen to compile the whole system (at least on x86_64
and a few other platforms).

gmp-5.1.3 does not compile with clang-3.4rc1 (r195771) with the
default compilation flags used in the NetBSD build infrastructure.

The first error is:

--- toom44_mul.o ---
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/toom44_mul.c:209:52: error: '&' within '|' [-Werror,-Wbitwise-op-parentheses]
  flags = (enum toom7_flags) (flags | toom7_w3_neg & mpn_toom_eval_dgr3_pm1 (apx, amx, ap, n, s, tp));
                                    ~ ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/toom44_mul.c:209:52: note: place parentheses around the '&' expression to silence this warning
  flags = (enum toom7_flags) (flags | toom7_w3_neg & mpn_toom_eval_dgr3_pm1 (apx, amx, ap, n, s, tp));

I fixed this by adding parentheses around the & part (after testing
that this binds stronger than | in gcc) and tried again, and had
similar failures in the next files:

--- toom53_mul.o ---
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/toom53_mul.c:102:52: error: '&' within '|' [-Werror,-Wbitwise-op-parentheses]
  flags = (enum toom7_flags) (flags | toom7_w1_neg & mpn_toom_eval_pm2 (as2, asm2, 4, ap, n, s, gp));
                                    ~ ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/toom53_mul.c:102:52: note: place parentheses around the '&' expression to silence this warning
  flags = (enum toom7_flags) (flags | toom7_w1_neg & mpn_toom_eval_pm2 (as2, asm2, 4, ap, n, s, gp));
                                                   ^


--- div_qr_2.o ---
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/div_qr_2.c:254:7: error: & has lower precedence than >=; >= will be evaluated first [-Werror,-Wparentheses]
      udiv_qr_4by2 (q1, q0, r1, r0, r1, r0, n1, n0, d1, d0, di1, di0);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/div_qr_2.c:146:37: note: expanded from macro 'udiv_qr_4by2'
    _mask = -(mp_limb_t) (r1 >= _q1 & (r1 > _q1 | r0 >= _q0));  /* (r1,r0) >= (q1,q0) */  \
                          ~~~~~~~~~~^
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/div_qr_2.c:254:7: note: place parentheses around the '>=' expression to silence this warning
      udiv_qr_4by2 (q1, q0, r1, r0, r1, r0, n1, n0, d1, d0, di1, di0);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/div_qr_2.c:146:37: note: expanded from macro 'udiv_qr_4by2'
    _mask = -(mp_limb_t) (r1 >= _q1 & (r1 > _q1 | r0 >= _q0));  /* (r1,r0) >= (q1,q0) */  \
                          ~~~~~~~~~ ^
/archive/foreign/src/external/lgpl3/gmp/lib/libgmp/../../dist/mpn/generic/div_qr_2.c:254:7: note: place parentheses around the & expression to evaluate it first
      udiv_qr_4by2 (q1, q0, r1, r0, r1, r0, n1, n0, d1, d0, di1, di0);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I checked the gmp hg repo yesterday and this code is unchanged in the
latest versions of the three files.

Before I start working on this, I'd like to know if I start adding
parentheses and send them to you, will they be accepted?

If not, what do you suggest?

Thanks,
 Thomas


More information about the gmp-bugs mailing list