This is an archive of the discontinued LLVM Phabricator instance.

[UBSan] Add returns-nonnull sanitizer.
ClosedPublic

Authored by samsonov on Aug 11 2014, 11:47 AM.

Details

Summary

This patch adds a runtime check verifying that functions
annotated with "returns_nonnull" attribute do in fact return nonnull pointers.
It is based on suggestion by Jakub Jelinek:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140623/223693.html.

Diff Detail

Event Timeline

samsonov updated this revision to Diff 12361.Aug 11 2014, 11:47 AM
samsonov retitled this revision from to [UBSan] Add returns-nonnull sanitizer..
samsonov updated this object.
samsonov edited the test plan for this revision. (Show Details)
samsonov added a reviewer: rsmith.
samsonov added a subscriber: Unknown Object (MLST).
rsmith accepted this revision.Aug 12 2014, 3:56 PM
rsmith edited edge metadata.

Looks good, a couple of minor comments.

projects/compiler-rt/lib/ubsan/ubsan_handlers.cc
319

Maybe "null pointer returned from function declared to never return null"? If we can produce a note pointing at the non-null attribute, that'd be even better.

tools/clang/lib/CodeGen/CGCall.cpp
2005

I don't think you should perform this address space check. LLVM is going to assume the pointer is non-null regardless of address space (see CodeGenModule::ConstructAttributeList) so we should sanitize it regardless.

This revision is now accepted and ready to land.Aug 12 2014, 3:56 PM
samsonov updated this revision to Diff 12428.Aug 12 2014, 5:29 PM
samsonov edited edge metadata.

Renamed the -fsanitize= flag value to "-fsanitize=returns-nonnull-attribute" and added the documentation.
Addressed reviewer's comments.

Thanks! Submitting this now.

projects/compiler-rt/lib/ubsan/ubsan_handlers.cc
319

Changed the error message as suggested.

tools/clang/lib/CodeGen/CGCall.cpp
2005

Done

samsonov updated this object.Aug 12 2014, 5:35 PM
samsonov closed this revision.Aug 12 2014, 5:35 PM