[clang-tools-extra] e09aa0d - [clangd][Tweak] Make sure enclosing function doesnt have invalid children

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 03:06:07 PDT 2022


Author: Kadir Cetinkaya
Date: 2022-10-07T12:00:22+02:00
New Revision: e09aa0d192e0ae240c55aaf8205e8320d49f9bdb

URL: https://github.com/llvm/llvm-project/commit/e09aa0d192e0ae240c55aaf8205e8320d49f9bdb
DIFF: https://github.com/llvm/llvm-project/commit/e09aa0d192e0ae240c55aaf8205e8320d49f9bdb.diff

LOG: [clangd][Tweak] Make sure enclosing function doesnt have invalid children

Differential Revision: https://reviews.llvm.org/D135257

Added: 
    

Modified: 
    clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
index 66fe4fdbfa2d3..4231de8cc45d6 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -248,6 +248,13 @@ const FunctionDecl *findEnclosingFunction(const Node *CommonAnc) {
       // FIXME: Support extraction from templated functions.
       if (Func->isTemplated())
         return nullptr;
+      for (const auto *S : Func->getBody()->children()) {
+        // During apply phase, we perform semantic analysis (e.g. figure out
+        // what variables requires hoisting). We cannot perform those when the
+        // body has invalid statements, so fail up front.
+        if (!S)
+          return nullptr;
+      }
       return Func;
     }
   }


        


More information about the cfe-commits mailing list