This is an archive of the discontinued LLVM Phabricator instance.

[ubsan] Extend the nonnull argument check to ObjC
ClosedPublic

Authored by vsk on Mar 3 2017, 7:59 PM.

Details

Summary

UBSan's nonnull argument check applies when a parameter has the
"nonnull" attribute. The check currently works for FunctionDecls, but
not for ObjCMethodDecls. This patch extends the check to work for ObjC.

To do this, I introduced a new AbstractCallee class to represent the
logical callee in a generic "call", and added a use of AbstractCallee to
CGObjC.cpp. This does not affect IRGen except to fix the UBSan check.

I opted not to reuse CGCalleeInfo for this because: 1) it isn't meant to
represent the callee itself, 2) it carries around an extra pointer for
the callee prototype, and 3) it's a bit tricky to repurpose (i.e it
really "wants" to live in CGCall.h).

Testing: check-clang, check-ubsan

Diff Detail

Repository
rL LLVM

Event Timeline

vsk created this revision.Mar 3 2017, 7:59 PM

Can the null check be performed in the callee?

That'd make this check work for a few more cases that this patch doesn't cover:

  • performSelector: messages
  • messages to id.
vsk added a comment.Mar 3 2017, 8:54 PM

Can the null check be performed in the callee?

Yes, but I think that would result in perplexing diagnostics, because we wouldn't be able to report the source location of the buggy calls.

That'd make this check work for a few more cases that this patch doesn't cover:

  • performSelector: messages
  • messages to id.

That's a good point, but sadly I don't see a way to diagnose these situations well with the current check. I think the best we can do is to check for nullability violations on assignment/return. I will upload a nullability "sanitizer" for review soon that does this.

jroelofs accepted this revision.Mar 3 2017, 9:12 PM

LGTM, by the way.

This revision is now accepted and ready to land.Mar 3 2017, 9:12 PM
aprantl added inline comments.Mar 4 2017, 11:02 AM
lib/CodeGen/CodeGenFunction.h
308 ↗(On Diff #90564)

The \brief is redundant (we use autobrief) and shouldn't be used any more.

This revision was automatically updated to reflect the committed changes.
vsk marked an inline comment as done.Mar 5 2017, 9:40 PM

Thanks for the reviews!

lib/CodeGen/CodeGenFunction.h
308 ↗(On Diff #90564)

I will fix this before committing.