Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -1732,7 +1732,7 @@ unsigned Prev = 0; unsigned SearchFrom = 0; llvm::Regex IncludeRegex( - R"(^[\t\ ]*#[\t\ ]*include[^"<]*(["<][^">]*[">]))"); + R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))"); SmallVector Matches; SmallVector IncludesInBlock; @@ -1762,20 +1762,21 @@ Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev); if (!Line.endswith("\\")) { if (IncludeRegex.match(Line, &Matches)) { + StringRef IncludeName = Matches[2]; unsigned Category; - if (LookForMainHeader && !Matches[1].startswith("<")) { + if (LookForMainHeader && !IncludeName.startswith("<")) { Category = 0; } else { Category = UINT_MAX; for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i) { - if (CategoryRegexs[i].match(Matches[1])) { + if (CategoryRegexs[i].match(IncludeName)) { Category = Style.IncludeCategories[i].Priority; break; } } } LookForMainHeader = false; - IncludesInBlock.push_back({Matches[1], Line, Prev, Category}); + IncludesInBlock.push_back({IncludeName, Line, Prev, Category}); } else if (!IncludesInBlock.empty()) { sortIncludes(Style, IncludesInBlock, Ranges, FileName, Replaces); IncludesInBlock.clear(); Index: unittests/Format/SortIncludesTest.cpp =================================================================== --- unittests/Format/SortIncludesTest.cpp +++ unittests/Format/SortIncludesTest.cpp @@ -40,6 +40,16 @@ "#include \"b.h\"\n")); } +TEST_F(SortIncludesTest, MixIncludeAndImport) { + EXPECT_EQ("#include \"a.h\"\n" + "#import \"b.h\"\n" + "#include \"c.h\"\n", + sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#import \"b.h\"\n")); +} + + TEST_F(SortIncludesTest, FixTrailingComments) { EXPECT_EQ("#include \"a.h\" // comment\n" "#include \"bb.h\" // comment\n"