This is an archive of the discontinued LLVM Phabricator instance.

Skip NonNull sema checks in unevaluated contexts.
ClosedPublic

Authored by EricWF on Oct 3 2015, 2:02 AM.

Details

Summary

Currently when a function annotated with attribute((nonnull)) is called in an unevaluated context with a null argument a -Wnonnull warning is emitted.
This warning seems like a false positive unless the call expression is potentially evaluated. Change this behavior so that the non-null warnings use DiagRuntimeBehavior so they wont emit when they won't be evaluated.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 36430.Oct 3 2015, 2:02 AM
EricWF retitled this revision from to Skip NonNull sema checks in unevaluated contexts..
EricWF updated this object.
EricWF added reviewers: rsmith, majnemer.
EricWF added subscribers: cfe-commits, mclow.lists.
rsmith accepted this revision.Oct 5 2015, 6:07 PM
rsmith edited edge metadata.

This seems reasonable.

I wonder if it might be better to also suppress warnings for dynamically-unreachable code (you can do this by changing the Diag calls inside CheckNonNullArguments to DiagRuntimeBehavior instead of the current patch). That would help for a case like:

#define SAFE_FOO(x) if (x) foo(x)
SAFE_FOO(0);

... but admittedly that's pretty contrived.

Anyway, this looks fine as far as it goes.

This revision is now accepted and ready to land.Oct 5 2015, 6:07 PM
EricWF added a comment.Oct 5 2015, 8:21 PM

DiagRuntimeBehavior seems like a better way to do this. I'll commit that change.

EricWF updated this revision to Diff 36910.Oct 8 2015, 5:18 PM
EricWF updated this object.
EricWF edited edge metadata.
EricWF closed this revision.Oct 8 2015, 5:19 PM