[clang] b2a4f64 - [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code (#82957)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 26 20:46:49 PST 2024
Author: Owen Pan
Date: 2024-02-26T20:46:46-08:00
New Revision: b2a4f64e19247d0553d3dc63af62b652664c3cd6
URL: https://github.com/llvm/llvm-project/commit/b2a4f64e19247d0553d3dc63af62b652664c3cd6
DIFF: https://github.com/llvm/llvm-project/commit/b2a4f64e19247d0553d3dc63af62b652664c3cd6.diff
LOG: [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code (#82957)
Added:
Modified:
clang/lib/Format/Format.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 794e326fb1c948..13588ff705f544 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3923,7 +3923,7 @@ FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
auto Extension = llvm::sys::path::extension(FileName);
// If there's no file extension (or it's .h), we need to check the contents
// of the code to see if it contains Objective-C.
- if (Extension.empty() || Extension == ".h") {
+ if (!Code.empty() && (Extension.empty() || Extension == ".h")) {
auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName;
Environment Env(Code, NonEmptyFileName, /*Ranges=*/{});
ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle());
More information about the cfe-commits
mailing list