This is an archive of the discontinued LLVM Phabricator instance.

Fix PR13910: Don't warn that __builtin_unreachable() is unreachable
ClosedPublic

Authored by arphaman on Oct 6 2016, 6:15 AM.

Details

Summary

This patch fixes the issue of clang emitting an unreachable warning when it encounters unreachable __builtin_unreachable() statements. It detects references to __builtin_unreachable and doesn't emit an unreachable warning for them.

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman updated this revision to Diff 73779.Oct 6 2016, 6:15 AM
arphaman retitled this revision from to Fix PR13910: Don't warn that __builtin_unreachable() is unreachable.
arphaman updated this object.
arphaman added reviewers: dblaikie, krememek.
arphaman set the repository for this revision to rL LLVM.
arphaman added a subscriber: cfe-commits.
arphaman updated this revision to Diff 73781.Oct 6 2016, 6:18 AM

Slight update: There's no need to pass CFGBlock into isBuiltinUnreachable.

aprantl added a subscriber: aprantl.Oct 6 2016, 9:50 AM
aprantl added inline comments.
lib/Analysis/ReachableCode.cpp
64 ↗(On Diff #73781)

Maybe also wrap the inner dyn_cast in an if for symmetry?

static bool isBuiltinUnreachable(const Stmt *S) {
  if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
    if (const auto *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()))
      return FDecl->getIdentifier() &&
             FDecl->getBuiltinID() == Builtin::BI__builtin_unreachable;
  return false;
}
arphaman updated this revision to Diff 73898.Oct 7 2016, 2:36 AM
arphaman marked an inline comment as done.

The updated patch uses Adrian's suggestion.

aprantl accepted this revision.Oct 7 2016, 9:19 AM
aprantl added a reviewer: aprantl.

Thanks, LGTM!

This revision is now accepted and ready to land.Oct 7 2016, 9:19 AM
This revision was automatically updated to reflect the committed changes.