qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/1] meson: Enable -Wshadow=local


From: Thomas Huth
Subject: Re: [PATCH 1/1] meson: Enable -Wshadow=local
Date: Thu, 26 Oct 2023 07:55:01 +0200
User-agent: Mozilla Thunderbird

On 26/10/2023 07.51, Warner Losh wrote:


On Wed, Oct 25, 2023, 11:31 PM Markus Armbruster <armbru@redhat.com <mailto:armbru@redhat.com>> wrote:

    Local variables shadowing other local variables or parameters make the
    code needlessly hard to understand.  Bugs love to hide in such code.
    Evidence: commit bbde656263d (migration/rdma: Fix save_page method to
    fail on polling error).

    Enable -Wshadow=local to prevent such issues.  Possible thanks to
    recent cleanups.  Enabling -Wshadow would prevent more issues, but
    we're not yet ready for that.

    As usual, the warning is only enabled when the compiler recognizes it.
    GCC does, Clang doesn't.

    Some shadowed locals remain in bsd-user.  Since BSD prefers Clang,
    let's not wait for its cleanup.

    Signed-off-by: Markus Armbruster <armbru@redhat.com
    <mailto:armbru@redhat.com>>
    ---
      meson.build | 1 +
      1 file changed, 1 insertion(+)

    diff --git a/meson.build b/meson.build
    index dcef8b1e79..89220443b8 100644
    --- a/meson.build
    +++ b/meson.build
    @@ -462,6 +462,7 @@ warn_flags = [
        '-Wno-tautological-type-limit-compare',
        '-Wno-psabi',
        '-Wno-gnu-variable-sized-type-not-at-end',
    +  '-Wshadow=local',


Does this work with clang? I've not had good luck enabling it.

The flags are added via cc.get_supported_arguments(warn_flags), so meson checks whether the compiler supports them before blindly adding them to the list. That means it should get ignored with Clang, i.e. we should be ok for the remaining spots in the bsd-user code, assuming that most FreeBSD users will use Clang to compile QEMU.

 Thomas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]