[llvm-branch-commits] [clang] 7b2d62f - [clang-format] PR42434 Remove preprocessor and pragma lines from ObjectiveC guess
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 10 03:18:46 PST 2020
Author: mydeveloperday
Date: 2020-12-10T11:13:22Z
New Revision: 7b2d62fd7f7befda2ce327d25075b0aac9bc6780
URL: https://github.com/llvm/llvm-project/commit/7b2d62fd7f7befda2ce327d25075b0aac9bc6780
DIFF: https://github.com/llvm/llvm-project/commit/7b2d62fd7f7befda2ce327d25075b0aac9bc6780.diff
LOG: [clang-format] PR42434 Remove preprocessor and pragma lines from ObjectiveC guess
clang-format see the `disable:` in __pragma(warning(disable:)) as ObjectiveC method call
Remove any line starting with `#` or __pragma line from being part of the ObjectiveC guess
https://bugs.llvm.org/show_bug.cgi?id=42434
Reviewed By: curdeius, krasimir
Differential Revision: https://reviews.llvm.org/D92922
Added:
Modified:
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index a3f740ff8692..4263f7b47e7c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2032,6 +2032,10 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
};
for (auto Line : AnnotatedLines) {
+ if (Line->First && (Line->First->TokenText.startswith("#") ||
+ Line->First->TokenText == "__pragma" ||
+ Line->First->TokenText == "_Pragma"))
+ continue;
for (const FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index e897402e502a..d3ea5c2b5880 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16713,6 +16713,15 @@ TEST_F(FormatTest, GuessLanguageWithCaret) {
guessLanguage("foo.h", "int(^foo[(kNumEntries + 10)])(char, float);"));
}
+TEST_F(FormatTest, GuessLanguageWithPragmas) {
+ EXPECT_EQ(FormatStyle::LK_Cpp,
+ guessLanguage("foo.h", "__pragma(warning(disable:))"));
+ EXPECT_EQ(FormatStyle::LK_Cpp,
+ guessLanguage("foo.h", "#pragma(warning(disable:))"));
+ EXPECT_EQ(FormatStyle::LK_Cpp,
+ guessLanguage("foo.h", "_Pragma(warning(disable:))"));
+}
+
TEST_F(FormatTest, FormatsInlineAsmSymbolicNames) {
// ASM symbolic names are identifiers that must be surrounded by [] without
// space in between:
More information about the llvm-branch-commits
mailing list