Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable -Wshadow=local #152

Open
kees opened this issue Sep 17, 2021 · 2 comments
Open

Enable -Wshadow=local #152

kees opened this issue Sep 17, 2021 · 2 comments

Comments

@kees
Copy link

kees commented Sep 17, 2021

This would protect the kernel from silent corruptions in overlapping macro variables, for example:

#define something(output, len) \
({ \
    size_t __len = (len); \
    if (__len == 5) \
        do_something(output, __len); \
    else \
         do_other_thing(output, __len); \
    result(output); \
})
...
int __len = 5;
...
something(buffer, __len);

https://godbolt.org/z/P1ox1xWPo

While GCC 4.8 improved global collisions, -Wshadow is still currently unusable:

./arch/x86/include/asm/bitops.h:283:28: warning: declaration of 'ffs' shadows a built-in function [-
Wshadow]                                                                                            
  283 | static __always_inline int ffs(int x)                                                       
      |                            ^~~                                                              

But instead, -Wshadow=local handles the cases that are the most interesting.

This is wider coverage than what might accidentally get caught by -Wunused-but-set-variable, which also has a lot of false positives:
https://lore.kernel.org/r/[email protected]/
https://lore.kernel.org/r/[email protected]/

@kees kees changed the title Enable -Wshadow Enable -Wshadow=local Sep 17, 2021
@kees
Copy link
Author

kees commented Sep 17, 2021

Dealing with the explicit shadowing in the __wait_event() macro family looking extremely difficult to deal with.

@kees
Copy link
Author

kees commented Apr 16, 2024

Potential __wait_event() cleanup has been proposed: https://lore.kernel.org/lkml/[email protected]/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant