[PATCH] D15324: [Sema] Emit warnings when comparing result of a function with `returns_nonnull` to null

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 7 22:41:16 PST 2015


george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rtrieu.
george.burgess.iv added a subscriber: cfe-commits.

Addresses a problem brought up by Xavier here: http://permalink.gmane.org/gmane.comp.compilers.clang.devel/46163

tl;dr: We get a warning on the following code

```
void foo(void *p) __attribute__((nonnull(1))) {
	if (p == NULL) {} // warning: always equal to false
}
```

…But not this code:

```
void foo() __attribute__((returns_nonnull));
int main() {
	if (foo() == NULL) {} // no warning
}
```

This patch makes us give a warning in the second case.

http://reviews.llvm.org/D15324

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/nonnull.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15324.42139.patch
Type: text/x-patch
Size: 5697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151208/6f2257f2/attachment.bin>


More information about the cfe-commits mailing list