This is an archive of the discontinued LLVM Phabricator instance.

[-Wcompletion-handler] Support checks with builtins
ClosedPublic

Authored by vsavchenko on Feb 8 2021, 7:53 AM.

Details

Summary

It is very common to check callbacks and completion handlers for null.
This patch supports such checks using built-in functions:

  • __builtin_expect
  • __builtin_expect_with_probablity
  • __builtin_unpredictable

rdar://73455388

Diff Detail

Event Timeline

vsavchenko created this revision.Feb 8 2021, 7:53 AM
vsavchenko requested review of this revision.Feb 8 2021, 7:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2021, 7:53 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
NoQ accepted this revision.Feb 8 2021, 7:13 PM

Aha, yup, makes sense!

clang/lib/Analysis/CalledOnceCheck.cpp
343

Otherwise it's a compile error and analysis based warnings aren't run when there are compile errors, right? If it was a normal function call there's no way we would have gotten away with such assertion. Like, even if it was a standard library function the user could still override that. But for builtins I guess that should work.

This revision is now accepted and ready to land.Feb 8 2021, 7:13 PM
vsavchenko added inline comments.Feb 8 2021, 11:32 PM
clang/lib/Analysis/CalledOnceCheck.cpp
343

Exactly, we have a somewhat similar assertion in the analyzer

This revision was landed with ongoing or failed builds.Feb 9 2021, 12:36 AM
This revision was automatically updated to reflect the committed changes.