[clang] 0e89f1c - [clang-format][NFC] Don't run any passes if Environment::make fails

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 14 10:27:27 PST 2022


Author: Owen Pan
Date: 2022-12-14T10:27:05-08:00
New Revision: 0e89f1cca495055795d97b17cb38d43d0c9a7ec1

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

LOG: [clang-format][NFC] Don't run any passes if Environment::make fails

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

Added: 
    

Modified: 
    clang/lib/Format/Format.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index b71add7f2e280..c1e382a681c2f 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3382,6 +3382,11 @@ reformat(const FormatStyle &Style, StringRef Code,
     return {tooling::Replacements(), 0};
   }
 
+  auto Env = Environment::make(Code, FileName, Ranges, FirstStartColumn,
+                               NextStartColumn, LastStartColumn);
+  if (!Env)
+    return {};
+
   typedef std::function<std::pair<tooling::Replacements, unsigned>(
       const Environment &)>
       AnalyzerPass;
@@ -3452,10 +3457,6 @@ reformat(const FormatStyle &Style, StringRef Code,
     });
   }
 
-  auto Env = Environment::make(Code, FileName, Ranges, FirstStartColumn,
-                               NextStartColumn, LastStartColumn);
-  if (!Env)
-    return {};
   std::optional<std::string> CurrentCode;
   tooling::Replacements Fixes;
   unsigned Penalty = 0;


        


More information about the cfe-commits mailing list