Skip to contentSkip to conversation

configure: Disable -Wtautological-type-limit-compare

PATCH In review Richard Henderson 7 participants 12 messages Jun 4, 2020 – Jun 8, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: Disable -Wtautological-type-limit-compare

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +2 -0
index f087d2bcd1..693f01327f 100755
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +0 -0
index f087d2bcd1..693f01327f 100755

configure gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" · line 2016

Quoted 8 lines
configure +2 -0
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
Tested-by Reviewed-by on v1 1/1
#2 lore raw
In reply to Richard Henderson
Quoted 7 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

I dare to add:

Quoted 19 lines
---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +2 -0
index f087d2bcd1..693f01327f 100755
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
#3 lore raw
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

Quoted 3 lines

Clarifying: I tested with clang-10, but Alex/Cornelia reported on IRC the failure persist with clang-9 until using --disabler-werror.

Quoted 24 lines

I dare to add:

Quoted 19 lines
---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +2 -0
index f087d2bcd1..693f01327f 100755
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
#4 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

Quoted 6 lines
Quoted 3 lines

Clarifying: I tested with clang-10, but Alex/Cornelia reported on IRC the failure persist with clang-9 until using --disabler-werror.

Does -Wno-tautological-constant-compare help on Clang-9 instead?

Thomas

Quoted 26 lines
Quoted 24 lines

I dare to add:

Quoted 19 lines
---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +2 -0
index f087d2bcd1..693f01327f 100755
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
Tested-by
#5 lore raw
Quoted 11 lines · Thomas Huth
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Clarifying: I tested with clang-10, but Alex/Cornelia reported on IRC the failure persist with clang-9 until using --disabler-werror.

Does -Wno-tautological-constant-compare help on Clang-9 instead?

Yeah that variant works for clang-9

Quoted 30 lines

Thomas

Quoted 26 lines
Quoted 24 lines

I dare to add:

Quoted 19 lines
---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +2 -0
index f087d2bcd1..693f01327f 100755
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
Signature · 1 line
Alex Bennée
Reviewed-by on v1 1/1
#6 lore raw
In reply to Richard Henderson
Quoted 6 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

While I proposed an alternative fix that was able to silence the most recent error without #if, I do like this approach better - the warning causes far more false positives than flagging actual bugs, especially when we write code to allow 32->32, 64->32, and 64->64 host->emulation paths, where one or more of those need the check but the others really do a tautological compare, by the nature of the types involved.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 1/1
#7 lore raw
In reply to Richard Henderson
Quoted 17 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)
configure +0 -0
index f087d2bcd1..693f01327f 100755

configure gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" · line 2013

Quoted 5 lines
configure +2 -0
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+

nit: the pattern is reversed compared to the previous lines (foo $gcc_flags)

I had exactly the same patch in my local tree but it wasn't enough for clang-9 which I was using for a sanitiser build. I ended up having to apply --disable-werrror to the configuration.

Anyway:

Signature · 1 line
Alex Bennée
#8 lore raw
Quoted 15 lines · Alex Bennée
Quoted 12 lines · Richard Henderson

Clang 10 enables this by default with -Wtype-limit.

All of the instances flagged by this Werror so far have been cases in which we really do want the compiler to optimize away the test completely. Disabling the warning will avoid having to add ifdefs to work around this.

---
 configure | 2 ++
 1 file changed, 2 insertions(+)
Quoted 12 lines

configure gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" · line 2013

Quoted 10 lines
configure +2 -0
index f087d2bcd1..693f01327f 100755
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+

nit: the pattern is reversed compared to the previous lines (foo $gcc_flags)

Not a nit. The -Wno- must follow -Wtype-limit, or -Wtype-limit will turn it back on.

r~

Quoted 9 lines

I had exactly the same patch in my local tree but it wasn't enough for clang-9 which I was using for a sanitiser build. I ended up having to apply --disable-werrror to the configuration.

Anyway:

#9 lore raw
Quoted 13 lines · Richard Henderson
Quoted 10 lines · Alex Bennée

configure gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" · line 2013

Quoted 8 lines
configure +2 -0
@@ -2009,6 +2009,8 @@ gcc_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
 gcc_flags="-Wendif-labels -Wno-shift-negative-value $gcc_flags"
 gcc_flags="-Wno-initializer-overrides -Wexpansion-to-defined $gcc_flags"
 gcc_flags="-Wno-string-plus-int -Wno-typedef-redefinition $gcc_flags"
+gcc_flags="$gcc_flags -Wno-tautological-type-limit-compare"
+

nit: the pattern is reversed compared to the previous lines (foo $gcc_flags)

Quoted 2 lines

Not a nit. The -Wno- must follow -Wtype-limit, or -Wtype-limit will turn it back on.

If there's an ordering requirement here we should make it clearer, or somebody is going to do the obvious "tidying up" at some point in the future.

Perhaps this whole set of lines should be rearranged, something like:

# Enable these warnings if the compiler supports them:
warn_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits" warn_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $warn_flags" warn_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $warn_flags" warn_flags="-Wendif-labels -Wexpansion-to-defined $warn_flags"
# Now disable sub-types of warning we don't want but which are

# enabled by some of the warning flags we do want; these must come
# later in the compiler command line than the enabling warning options.
nowarn_flags="-Wno-missing-include-dirs -Wno-shift-negative-value"
nowarn_flags="-Wno-initializer-overrides $nowarn_flags"
nowarn_flags="-Wno-string-plus-int -Wno-typedef-redefinition $nowarn_flags"
warn_flags="$warn_flags $nowarn_flags"

(is there a nicer shell idiom for creating a variable that's a long string of stuff without having over-long lines?)

It's also tempting to pull the handful of warning related options currently set directly in QEMU_CFLAGS (-Wall, etc) into this same set of variables.

thanks
-- PMM

#10 lore raw
Quoted 20 lines · Peter Maydell

If there's an ordering requirement here we should make it clearer, or somebody is going to do the obvious "tidying up" at some point in the future.

Perhaps this whole set of lines should be rearranged, something like:

# Enable these warnings if the compiler supports them:
warn_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits" warn_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $warn_flags" warn_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $warn_flags" warn_flags="-Wendif-labels -Wexpansion-to-defined $warn_flags"
# Now disable sub-types of warning we don't want but which are

# enabled by some of the warning flags we do want; these must come
# later in the compiler command line than the enabling warning options.
nowarn_flags="-Wno-missing-include-dirs -Wno-shift-negative-value"
nowarn_flags="-Wno-initializer-overrides $nowarn_flags"
nowarn_flags="-Wno-string-plus-int -Wno-typedef-redefinition $nowarn_flags"
warn_flags="$warn_flags $nowarn_flags"
Quoted 2 lines

(is there a nicer shell idiom for creating a variable that's a long string of stuff without having over-long lines?)

You could always do:

# Append $2 into the variable named $1, with space separation

add_to () {
    eval $1=\${$1:+\"\$$1 \"}\$2
}

add_to warn_flags -Wold-style-declaration
add_to warn_flags -Wold-style-definition
add_to warn_flags -Wtype-limits
...
add_to nowarn_flags -Wno-string-plus-int
add_to nowarn_flags -Wno-typedef-redefinition
warn_flags="$warn_flags $nowarn_flags"

Quoted 5 lines

It's also tempting to pull the handful of warning related options currently set directly in QEMU_CFLAGS (-Wall, etc) into this same set of variables.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#11 lore raw

пет, 5. јун 2020. у 20:28 Eric Blake <[email protected]> је написао/ла:

Quoted 33 lines · Peter Maydell
Quoted 21 lines

If there's an ordering requirement here we should make it clearer, or somebody is going to do the obvious "tidying up" at some point in the future.

Perhaps this whole set of lines should be rearranged, something like:

# Enable these warnings if the compiler supports them:
warn_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits" warn_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $warn_flags" warn_flags="-Wno-missing-include-dirs -Wempty-body -Wnested-externs $warn_flags" warn_flags="-Wendif-labels -Wexpansion-to-defined $warn_flags"
# Now disable sub-types of warning we don't want but which are

# enabled by some of the warning flags we do want; these must come
# later in the compiler command line than the enabling warning options.
nowarn_flags="-Wno-missing-include-dirs -Wno-shift-negative-value"
nowarn_flags="-Wno-initializer-overrides $nowarn_flags"
nowarn_flags="-Wno-string-plus-int -Wno-typedef-redefinition $nowarn_flags"
warn_flags="$warn_flags $nowarn_flags"
Quoted 2 lines

(is there a nicer shell idiom for creating a variable that's a long string of stuff without having over-long lines?)

You could always do:

# Append $2 into the variable named $1, with space separation

add_to () {
     eval $1=\${$1:+\"\$$1 \"}\$2
}
Quoted 8 lines

add_to warn_flags -Wold-style-declaration
add_to warn_flags -Wold-style-definition
add_to warn_flags -Wtype-limits
...
add_to nowarn_flags -Wno-string-plus-int
add_to nowarn_flags -Wno-typedef-redefinition
warn_flags="$warn_flags $nowarn_flags"

I support the ideas outlined above by Peter and Eric.

Especially I like "one line per flag" approach, implicitly introduced by Eric.

This is a very good opportunity to bring some order and beauty into this, frankly, ugly piece of code.

Thanks
Aleksandar

Quoted 12 lines
Quoted 5 lines

It's also tempting to pull the handful of warning related options currently set directly in QEMU_CFLAGS (-Wall, etc) into this same set of variables.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org