configure: Fix compiler warnings in config.log
cover configure: Fix compiler warnings in config.log
Recently some patches were sent from Peter Maydell to improve the output in config.log.
This new patch series also improves that output by eliminating some compiler warnings.
Here is the result of a typical QEMU configuration:
without patch series
296 lines in config.log with 78 compilations, 69 errors and 107 warnings
with patch series applied
152 lines in config.log with 75 compilations, 24 errors and 30 warnings
It is possible to apply only some of the patches (they don't depend on each other).
Regards,
Stefan Weil
[PATCH 01/11] configure: Fix compiler warnings in config.log (always return a value from main) [PATCH 02/11] configure: Fix compiler warnings in config.log (old-style function definition) [PATCH 03/11] configure: Fix compiler warning in config.log (integer from pointer) [PATCH 04/11] configure: Fix compiler warnings in config.log (null arguments) [PATCH 05/11] configure: Fix compiler warning in config.log (unused variable) [PATCH 06/11] configure: Fix compiler warning in config.log (macro redefined) [PATCH 07/11] configure: Fix compiler warnings in config.log (uninitialized variable) [PATCH 08/11] configure: Fix compiler warning in config.log (undefined NULL) [PATCH 09/11] configure: Fix compiler warning in config.log (value was never used) [PATCH 10/11] configure: Fix compiler warnings in config.log (statement without effect) [PATCH 11/11] configure: Improve Xen autodetection for hosts without Xen
PATCH 1/11 configure: Fix compiler warnings in config.log (always return a value from main)
Fix several "warning: control reaches end of non-void function".
--- configure | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
configure +4 -3
@@ -1082,7 +1082,7 @@ fi # check that the C compiler works. cat > $TMPC <<EOF -int main(void) {} +int main(void) { return 0; } EOF if compile_object ; then
@@ -2651,7 +2651,7 @@ ucontext_coroutine=no if test "$darwin" != "yes"; then cat > $TMPC << EOF #include <ucontext.h> -int main(void) { makecontext(0, 0, 0); } +int main(void) { makecontext(0, 0, 0); return 0; } EOF if compile_prog "" "" ; then ucontext_coroutine=yes
@@ -2664,7 +2664,7 @@ fi open_by_hande_at=no cat > $TMPC << EOF #include <fcntl.h> -int main(void) { struct file_handle fh; open_by_handle_at(0, &fh, 0); } +int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); } EOF if compile_prog "" "" ; then open_by_handle_at=yes
@@ -2677,6 +2677,7 @@ linux_magic_h=no cat > $TMPC << EOF #include <linux/magic.h> int main(void) { + return 0; } EOF if compile_prog "" "" ; then
Signature · 1 line
1.7.2.5
PATCH 2/11 configure: Fix compiler warnings in config.log (old-style function definition)
In reply to Stefan Weilwarning: function declaration isn’t a prototype
In function ‘foo’:
warning: old-style function definition
The function name was changed, too, to avoid an additional warning.
--- configure | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
configure +2 -2
@@ -1274,11 +1274,11 @@ if test "$nptl" != "no" ; then cat > $TMPC <<EOF #include <sched.h> #include <linux/futex.h> -void foo() -{ +int main(void) { #if !defined(CLONE_SETTLS) || !defined(FUTEX_WAIT) #error bork #endif + return 0; } EOF
Signature · 1 line
1.7.2.5
PATCH 3/11 configure: Fix compiler warning in config.log (integer from pointer)
In reply to Stefan Weilwarning: return makes integer from pointer without a cast
--- configure | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
configure +5 -1
@@ -1841,7 +1841,11 @@ if test "$curses" != "no" ; then #ifdef __OpenBSD__ #define resize_term resizeterm #endif -int main(void) { resize_term(0, 0); return curses_version(); } +int main(void) { + const char *s = curses_version(); + resize_term(0, 0); + return s != (const char *)0; +} EOF for curses_lib in $curses_list; do if compile_prog "" "$curses_lib" ; then
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH 03/11] configure: Fix compiler warning in config.log (integer from pointer)
Quoted 12 lines · Stefan Weil
warning: return makes integer from pointer without a cast
Signed-off-by Stefan Weil <[email protected]>---
configure | 6 +++++-1 files changed, 5 insertions(+), 1 deletions(-)configure +0
-0
configure if test "$curses" != "no" ; then · line 1847
Quoted 8 lines
configure +4
-1@@ -1841,7 +1841,11 @@ if test "$curses" != "no" ; then #ifdef __OpenBSD__ #define resize_term resizeterm #endif -int main(void) { resize_term(0, 0); return curses_version(); } +int main(void) { + const char *s = curses_version(); + resize_term(0, 0); + return s != (const char *)0;
You don't need this cast, I think.
Quoted 6 lines
configure +1
-0+}EOF
forcurses_libin $curses_list; do
ifcompile_prog"" "$curses_lib" ; then
--
1.7.2.5
-- PMM
Re: [Qemu-devel] [PATCH 03/11] configure: Fix compiler warning in config.log (integer from pointer)
Am 17.12.2011 12:29, schrieb Peter Maydell:
Quoted 8 lines · Stefan Weil
Quoted 7 lines
warning: return makes integer from pointer without a cast
Signed-off-by Stefan Weil <[email protected]>--- configure | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
Quoted 15 lines
configure if test "$curses" != "no" ; then · line 1847
Quoted 13 lines
configure +4
-1@@ -1841,7 +1841,11 @@ if test "$curses" != "no" ; then #ifdef __OpenBSD__ #define resize_term resizeterm #endif -int main(void) { resize_term(0, 0); return curses_version(); } +int main(void) { + const char *s = curses_version(); + resize_term(0, 0); + return s != (const char *)0;You don't need this cast, I think.
Indeed, a quick test with gcc-4.4.5 shows no new warning when I remove the type cast. Are you sure that this works with all supported versions of gcc and any set of warning options?
Normally NULL is used for this kind of code, but it needs stddef.h. Typically NULL is defined to be ((void *)0 for C (that's the reason why I used a type cast, too). Only for C++ it is defined without a type cast.
The type cast won't harm and is not in "normal" code, so it can be committed as it is. I also don't mind if it is removed by whoever commits it. If it is preferred that I send an updated patch, I'd use NULL with stddef.h (just to be safe).
Regards,
Stefan Weil
Re: [Qemu-devel] [PATCH 03/11] configure: Fix compiler warning in config.log (integer from pointer)
Quoted 8 lines · Stefan Weil
Am 17.12.2011 12:29, schrieb Peter Maydell:
Quoted 3 lines
Quoted 1 line
+ return s != (const char *)0;
You don't need this cast, I think.
Indeed, a quick test with gcc-4.4.5 shows no new warning when I remove the type cast. Are you sure that this works with all supported versions of gcc and any set of warning options?
Yes. Both 0 and (void*)0 are null pointer constants; comparing explicitly for "if (ptr != 0)" is equivalent to "if (ptr)"; qemu style prefers the latter but there are a few of the former in the codebase, so practically speaking we know it compiles fine.
Quoted 2 lines
Normally NULL is used for this kind of code, but it needs
stddef.h.
Only in some coding styles. NULL is just a convenience macro if you like that kind of thing.
Quoted 3 lines
Typically NULL is defined to be ((void *)0 for C (that's the reason why I used a type cast, too). Only for C++ it is defined without a type cast.
The C standard permits plain "0" as a definition of NULL.
Quoted 5 lines
The type cast won't harm and is not in "normal" code, so it can be committed as it is. I also don't mind if it is removed by whoever commits it. If it is preferred that I send an updated patch, I'd use NULL with
stddef.h(just to be safe).
We use plain 0 for a null pointer constant in various existing tests in configure; this is simpler and avoids dragging in stddef.h. I would prefer that.
-- PMM
Re: [Qemu-devel] [PATCH 03/11] configure: Fix compiler warning in config.log (integer from pointer)
Quoted 5 lines · Peter Maydell
Quoted 3 lines
Typically NULL is defined to be ((void *)0 for C (that's the reason why I used a type cast, too). Only for C++ it is defined without a type cast.
The C standard permits plain "0" as a definition of NULL.
POSIX concurs with the C standard that a plain "0" can be used for representing a null pointer, but requires that the macro NULL be defined as ((void*)0) as a tighter requirement than C.
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_244
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html#tag_13_47
Quoted 3 lines
We use plain 0 for a null pointer constant in various existing tests in configure; this is simpler and avoids dragging in
stddef.h. I would prefer that.
I agree that configure tests should be as small as possible while still being correct, and use of a 0 constant without a cast, rather than NULL, is appropriate in that context.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 3/11 configure: Fix compiler warning in config.log (integer from pointer)
In reply to Stefan Weilwarning: return makes integer from pointer without a cast
v2: Removed type cast.
--- configure | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
configure +5 -1
@@ -1841,7 +1841,11 @@ if test "$curses" != "no" ; then #ifdef __OpenBSD__ #define resize_term resizeterm #endif -int main(void) { resize_term(0, 0); return curses_version(); } +int main(void) { + const char *s = curses_version(); + resize_term(0, 0); + return s != 0; +} EOF for curses_lib in $curses_list; do if compile_prog "" "$curses_lib" ; then
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH v2 03/11] configure: Fix compiler warning in config.log (integer from pointer)
Quoted 5 lines · Stefan Weil
warning: return makes integer from pointer without a cast
v2: Removed type cast.
Signed-off-by Stefan Weil <[email protected]>
Quoted 25 lines
---
configure | 6 +++++-1 files changed, 5 insertions(+), 1 deletions(-)configure +5
-1@@ -1841,7 +1841,11 @@ if test "$curses" != "no" ; then #ifdef __OpenBSD__ #define resize_term resizeterm #endif -int main(void) { resize_term(0, 0); return curses_version(); } +int main(void) { + const char *s = curses_version(); + resize_term(0, 0); + return s != 0; +}EOF
forcurses_libin $curses_list; do
ifcompile_prog"" "$curses_lib" ; then
--
1.7.2.5
Signature · 2 lines
12345678901234567890123456789012345678901234567890123456789012345678901234567890 1 2 3 4 5 6 7 8
PATCH 4/11 configure: Fix compiler warnings in config.log (null arguments)
In reply to Stefan Weilwarning: null argument where non-null required (argument 1)
warning: null argument where non-null required (argument 3)
--- configure | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
configure +6 -1
@@ -1951,7 +1951,12 @@ PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2" pthread=no cat > $TMPC << EOF #include <pthread.h> -int main(void) { pthread_create(0,0,0,0); return 0; } +static void *f(void *p) { return NULL; } +int main(void) { + pthread_t thread; + pthread_create(&thread, 0, f, 0); + return 0; +} EOF if compile_prog "" "" ; then pthread=yes
Signature · 1 line
1.7.2.5
PATCH 5/11 configure: Fix compiler warning in config.log (unused variable)
In reply to Stefan Weilwarning: unused variable ‘iov’
--- configure | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
configure +1 -1
@@ -2060,7 +2060,7 @@ cat > $TMPC <<EOF #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> -int main(void) { struct iovec iov; return 0; } +int main(void) { return sizeof(struct iovec); } EOF iovec=no if compile_prog "" "" ; then
Signature · 1 line
1.7.2.5
PATCH 6/11 configure: Fix compiler warning in config.log (macro redefined)
In reply to Stefan Weilwarning: "_GNU_SOURCE" redefined
The macro is already defined on the command line.
--- configure | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
configure +0 -1
@@ -2251,7 +2251,6 @@ fi # signalfd probe signalfd="no" cat > $TMPC << EOF -#define _GNU_SOURCE #include <unistd.h> #include <sys/syscall.h> #include <signal.h>
Signature · 1 line
1.7.2.5
PATCH 7/11 configure: Fix compiler warnings in config.log (uninitialized variable)
In reply to Stefan Weilwarning: ‘fd’ is used uninitialized in this function
warning: ‘id’ is used uninitialized in this function
--- configure | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
configure +2 -2
@@ -2237,7 +2237,7 @@ cat > $TMPC << EOF int main(void) { - int len, fd; + int len, fd = 0; len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK); splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE); return 0;
@@ -2449,7 +2449,7 @@ fi cat > $TMPC <<EOF #include <signal.h> #include <time.h> -int main(void) { clockid_t id; return clock_gettime(id, NULL); } +int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); } EOF if compile_prog "" "" ; then
Signature · 1 line
1.7.2.5
PATCH 8/11 configure: Fix compiler warning in config.log (undefined NULL)
In reply to Stefan WeilAvoid the warning when probing for xfs.
--- configure | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
configure +1 -0
@@ -1670,6 +1670,7 @@ fi # xfsctl() probe, used for raw-posix if test "$xfs" != "no" ; then cat > $TMPC << EOF +#include <stddef.h> /* NULL */ #include <xfs/xfs.h> int main(void) {
Signature · 1 line
1.7.2.5
PATCH 9/11 configure: Fix compiler warning in config.log (value was never used)
In reply to Stefan Weil--- configure | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
configure +1 -2
@@ -2269,8 +2269,7 @@ cat > $TMPC << EOF int main(void) { - int efd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); - return 0; + return eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); } EOF if compile_prog "" "" ; then
Signature · 1 line
1.7.2.5
PATCH 10/11 configure: Fix compiler warnings in config.log (statement without effect)
In reply to Stefan Weil--- configure | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
configure +3 -4
@@ -2074,7 +2074,7 @@ cat > $TMPC <<EOF #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> -int main(void) { preadv; } +int main(void) { return preadv == preadv; } EOF preadv=no if compile_prog "" "" ; then
@@ -2107,7 +2107,7 @@ if test "$opengl" != "no" ; then #include <X11/Xlib.h> #include <GL/gl.h> #include <GL/glx.h> -int main(void) { GL_VERSION; return 0; } +int main(void) { return GL_VERSION != 0; } EOF if compile_prog "" "-lGL" ; then opengl=yes
@@ -2369,8 +2369,7 @@ int main(void) * warning but not an error, and will proceed to fail the * qemu compile where we compile with -Werror.) */ - epoll_create1; - return 0; + return epoll_create1 == epoll_create1; } EOF if compile_prog "$ARCH_CFLAGS" "" ; then
Signature · 1 line
1.7.2.5
PATCH 11/11 configure: Improve Xen autodetection for hosts without Xen
In reply to Stefan WeilWith this patch, it only takes one test (instead of four) to detect that there is no Xen support at all.
For most build hosts, this will reduce the time configure needs. It will also reduce noisy output in config.log.
Build hosts with Xen now need up to five (instead of up to four) tests. They get improved diagnostics when Xen support fails.
--- configure | 29 +++++++++++++++++++++++++---- 1 files changed, 25 insertions(+), 4 deletions(-)
configure +25 -4
@@ -1317,10 +1317,30 @@ fi if test "$xen" != "no" ; then xen_libs="-lxenstore -lxenctrl -lxenguest" - # Xen unstable + # First we test whether Xen headers and libraries are available. + # If no, we are done and there is no Xen support. + # If yes, more tests are run to detect the Xen version. + + # Xen (any) cat > $TMPC <<EOF #include <xenctrl.h> #include <xs.h> +int main(void) { + return 0; +} +EOF + if ! compile_prog "" "$xen_libs" ; then + # Xen not found + if test "$xen" = "yes" ; then + feature_not_found "xen" + fi + xen=no + + # Xen unstable + elif ( + cat > $TMPC <<EOF +#include <xenctrl.h> +#include <xs.h> #include <stdint.h> #include <xen/hvm/hvm_info_table.h> #if !defined(HVM_MAX_VCPUS)
@@ -1336,7 +1356,8 @@ int main(void) { return 0; } EOF - if compile_prog "" "$xen_libs" ; then + compile_prog "" "$xen_libs" + ) ; then xen_ctrl_version=410 xen=yes
@@ -1407,10 +1428,10 @@ EOF xen_ctrl_version=330 xen=yes - # Xen not found or unsupported + # Xen version unsupported else if test "$xen" = "yes" ; then - feature_not_found "xen" + feature_not_found "xen (unsupported version)" fi xen=no fi
Signature · 1 line
1.7.2.5
Re: [Qemu-devel] [PATCH 11/11] configure: Improve Xen autodetection for hosts without Xen
Quoted 8 lines · Stefan Weil
With this patch, it only takes one test (instead of four) to detect that there is no Xen support at all.
For most build hosts, this will reduce the time configure needs. It will also reduce noisy output in config.log.
Build hosts with Xen now need up to five (instead of up to four) tests. They get improved diagnostics when Xen support fails.
good idea, thanks for the patch
Quoted 5 lines · Stefan Weil
Recently some patches were sent from Peter Maydell to improve the output in config.log.
This new patch series also improves that output by eliminating some compiler warnings.
All except 03/11:
-- PMM