[Sema] Add warning when comparing nonnull and null
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 8 Dec 2015 22:02:00 +0000 (22:02 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 8 Dec 2015 22:02:00 +0000 (22:02 +0000)
commit850269a47eed94efc2620dde5fa7473e9d6bab9a
treeb4d318b3488f3db333f905327a1f2690091e075e
parent297916273244b8877631027b68a8911b737bb47b
[Sema] Add warning when comparing nonnull and null

Currently, we emit warnings in some cases where nonnull function
parameters are compared against null. This patch extends this support
to warn when comparing the result of `returns_nonnull` functions
against null.

More specifically, we will now warn cases like:

int *foo() __attribute__((returns_nonnull));
int main() {
  if (foo() == NULL) {} // warning: will always evaluate to false
}

Differential Revision: http://reviews.llvm.org/D15324

llvm-svn: 255058
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/ScopeInfo.h
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/nonnull.c