Discussion:
test-intprops.c: many new warnings
Jim Meyering
2011-05-24 19:36:45 UTC
Permalink
Still trying the latest from gnulib via coreutils,
"make check" was inundated with new warnings.
Nearly 500 lines worth.

Of course, I could simply turn off the warnings and/or -Werror
when building in gnulib-tests/, but I'd rather not.
I'll defer "upgrading to the latest" for now ;-)

...
Making check in gnulib-tests
...
test-intprops.c: In function 'main':
test-intprops.c:142:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:142:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:142:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:142:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:143:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
...
test-intprops.c:164:3: error: string length '4422' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:166:3: error: string length '5865' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:172:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:172:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:172:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:172:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:172:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:172:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:175:3: error: string length '4096' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:178:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:178:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
...
test-intprops.c:192:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:192:3: error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
test-intprops.c:192:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
...
test-intprops.c:215:3: error: string length '4605' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:216:3: error: string length '4241' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:219:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
...
test-intprops.c:240:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:240:3: error: string length '4143' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:240:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
...
test-intprops.c:241:3: error: string length '5235' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:241:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
...
test-intprops.c:241:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:241:3: error: string length '4521' is greater than the length '4095' ISO C99 compilers are required to support [-Werror=overlength-strings]
test-intprops.c:245:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
test-intprops.c:245:3: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
...
cc1: all warnings being treated as errors

make[5]: *** [test-intprops.o] Error 1
make[5]: Leaving directory `/h/j/w/co/cu/gnulib-tests'
make[4]: *** [check-am] Error 2
make[4]: Leaving directory `/h/j/w/co/cu/gnulib-tests'
make[3]: *** [check-recursive] Error 1
make[3]: Leaving directory `/h/j/w/co/cu/gnulib-tests'
make[2]: *** [check] Error 2
make[2]: Leaving directory `/h/j/w/co/cu/gnulib-tests'
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory `/h/j/w/co/cu'
make: *** [check] Error 2
Paul Eggert
2011-05-24 23:50:41 UTC
Permalink
Post by Jim Meyering
"make check" was inundated with new warnings.
Nearly 500 lines worth.
Thanks, I fixed those by pushing the following two patches:

---
ChangeLog | 9 +++++++++
lib/intprops.h | 8 ++++----
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 270866e..fee8b5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-05-24 Paul Eggert <***@cs.ucla.edu>
+
+ intprops: shorten, to pacify gcc -Woverlength-strings
+ * lib/intprops.h (_GL_INT_CONVERT, _GL_INT_NEGATE_CONVERT):
+ (_GL_BINARY_OP_OVERFLOW): Say "0 * (x)" rather than "(x) - (x)",
+ so that, for example, verify (INT_MULTIPLY_OVERFLOW (...)) is less
+ likely to run afoul of C compiler limits for string constant lengths.
+ See <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00528.html>.
+
2011-05-24 Eric Blake <***@redhat.com>

docs: document recently fixed glibc printf bug
diff --git a/lib/intprops.h b/lib/intprops.h
index 293204a..d722648 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -25,11 +25,11 @@
/* Return a integer value, converted to the same type as the integer
expression E after integer type promotion. V is the unconverted value.
E should not have side effects. */
-#define _GL_INT_CONVERT(e, v) ((e) - (e) + (v))
+#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))

/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
<http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00406.html>. */
-#define _GL_INT_NEGATE_CONVERT(e, v) ((e) - (e) - (v))
+#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v))

/* The extra casts in the following macros work around compiler bugs,
e.g., in Cray C 5.0.3.0. */
@@ -314,7 +314,7 @@
Arguments should be free of side effects. */
#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
op_result_overflow (a, b, \
- _GL_INT_MINIMUM ((b) - (b) + (a)), \
- _GL_INT_MAXIMUM ((b) - (b) + (a)))
+ _GL_INT_MINIMUM (0 * (b) + (a)), \
+ _GL_INT_MAXIMUM (0 * (b) + (a)))

#endif /* _GL_INTPROPS_H */
--
1.7.4.4



---
ChangeLog | 6 ++++++
tests/test-intprops.c | 6 ++++++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fee8b5a..390d4e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2011-05-24 Paul Eggert <***@cs.ucla.edu>

+ test-intprops: disable -Wtype-limits diagnostics
+ * tests/test-intprops.c: Use a pragma to ignore -Wtype-limits
+ diagnostics. Otherwise, the integer overflow macros generate many
+ diagnostics. Reported by Jim Meyering in
+ <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00528.html>.
+
intprops: shorten, to pacify gcc -Woverlength-strings
* lib/intprops.h (_GL_INT_CONVERT, _GL_INT_NEGATE_CONVERT):
(_GL_BINARY_OP_OVERFLOW): Say "0 * (x)" rather than "(x) - (x)",
diff --git a/tests/test-intprops.c b/tests/test-intprops.c
index 8fc582b..1a34d77 100644
--- a/tests/test-intprops.c
+++ b/tests/test-intprops.c
@@ -16,6 +16,12 @@

/* Written by Paul Eggert. */

+/* Tell gcc not to warn about the many (X < 0) expressions that
+ the overflow macros expand to. */
+#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wtype-limits"
+#endif
+
#include <config.h>

#include "intprops.h"
--
1.7.4.4
Eric Blake
2011-05-25 00:06:55 UTC
Permalink
Post by Paul Eggert
+++ b/tests/test-intprops.c
@@ -16,6 +16,12 @@
/* Written by Paul Eggert. */
+/* Tell gcc not to warn about the many (X < 0) expressions that
+ the overflow macros expand to. */
+#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
+# pragma GCC diagnostic ignored "-Wtype-limits"
+#endif
Would it be possible instead to write forwarding macros? That is, the
outer macro calls concat(name,test(params)) where test expands to either
0 or 1, at which point name##result can be used to call name0 for the
unsigned case (no X < 0) or name1 for the signed case (including X < 0)
checks?

Otherwise, we are just disabling the warnings for this test, but the
warnings will still byte us in regular code. I guess I'll try to find
time to play with the idea instead.
--
Eric Blake ***@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
Paul Eggert
2011-05-25 07:27:32 UTC
Permalink
Post by Eric Blake
Would it be possible instead to write forwarding macros?
Sorry, I don't see how. The macros might expand to runtime tests.
Post by Eric Blake
Otherwise, we are just disabling the warnings for this test, but the
warnings will still byte us in regular code.
-Wtype-limits is rarely used, and for good reason: it cries
wolf too often. If this turns into an issue, I suppose we can look
for workarounds, but I'm not relishing the opportunity.

Jim Meyering
2011-05-25 06:09:29 UTC
Permalink
Post by Jim Meyering
"make check" was inundated with new warnings.
Nearly 500 lines worth.
Those look fine and work for me.
Thanks!
Loading...