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

no warnings with -Waddress #42992

Closed
llvmbot opened this issue Oct 11, 2019 · 4 comments
Closed

no warnings with -Waddress #42992

llvmbot opened this issue Oct 11, 2019 · 4 comments
Labels
bugzilla Issues migrated from bugzilla clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 11, 2019

Bugzilla Link 43647
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

clang-10 falls to emit the warning for the following:

$ cat s.c
int main()
{
int *a = (void *) 0;
int b = (&a) == ((void *) 0);
return b;
}

$ clang-10 -Weverything -pedantic s.c

clang version 10.0.0 (https://github.com/llvm/llvm-project.git 49c4e58)
Target: x86_64-unknown-linux-gnu
Thread model: posix

[-Waddress] is enabled by default in Clang, but do not issue the warning. When compiled with GCC, warnings such as:

$ gcc -Wall s.c
s.c: In function ‘main’:
s.c:4:16: warning:the comparison will always evaluate as ‘false’ for the address of ‘a’ will never be NULL [-Waddress]
4 | int b = (&a) == ((void *) 0);
| ^~

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@Quuxplusone Quuxplusone added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 20, 2022
@Krishna-13-cyber
Copy link
Contributor

Hi!,
I am trying to solve this issue by targeting def warn_null_pointer_compare which does not have variable at present, I suppose due to which it does not catch the address of the pointer to variable.
Please do let me know if its a right approach and on the correct track.
CC: @tbaederr @AaronBallman @cjdb @Quuxplusone

@AaronBallman
Copy link
Collaborator

Please do let me know if its a right approach and on the correct track.

I think it's actually a bit easier than that, even. It looks like Sema::DiagnoseAlwaysNonNullPointer() is not skipping the paren expression node. When you remove the parens from (&a), we diagnose correctly: https://godbolt.org/z/EWTYWqP9Y

I'd recommend looking through that function to see where we're skipping over nodes we don't care about and ensure we skip over paren AST nodes as well.

@Krishna-13-cyber
Copy link
Contributor

Thanks a lot @AaronBallman !
I will work on the suggested approach.

@Krishna-13-cyber
Copy link
Contributor

image
I have updated with a patch https://reviews.llvm.org/D149000
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

4 participants