Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code #82957

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Feb 26, 2024

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 26, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/82957.diff

1 Files Affected:

  • (modified) clang/lib/Format/Format.cpp (+1-1)
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f6b52510099a7..00ffc6718e052b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3920,7 +3920,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());

@owenca owenca merged commit b2a4f64 into llvm:main Feb 27, 2024
6 checks passed
@owenca owenca deleted the guessLanguage branch February 27, 2024 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants