[PATCH] D70569: [clangd] Allow extract-to-function on regions that always return.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 22 02:46:31 PST 2019


kadircet accepted this revision.
kadircet marked an inline comment as done.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!



================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:173
+bool alwaysReturns(const ExtractionZone &EZ) {
+  const Stmt *Last = EZ.Parent->Children.back()->ASTNode.get<Stmt>();
+  // Unwrap enclosing (unconditional) compound statement.
----------------
`EZ.getLastRootStmt()` instead of `EZ.Parent->Children.back()`


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:175
+  // Unwrap enclosing (unconditional) compound statement.
+  while (const auto *CS = llvm::dyn_cast<CompoundStmt>(Last))
+    if (CS->body_empty())
----------------
nit: braces


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:180
+      Last = CS->body_back();
+  return llvm::isa<ReturnStmt>(Last);
+}
----------------
what if there's a goto in the selection :P 


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp:611
+  // (Others are possible if there are conversions, but this seems clearest).
+  if (CapturedInfo.HasReturnStmt) {
+    // If the return is conditional, neither replacing the code with
----------------
nit: early exits


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70569/new/

https://reviews.llvm.org/D70569





More information about the cfe-commits mailing list