diff --git a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
index d247e1471cc80d..10536438e2fc55 100644
--- a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -401,7 +401,7 @@ void Minimizer::printToNewline(const char *&First, const char *const End) {
do {
// Iterate over strings correctly to avoid comments and newlines.
if (*Last == '"' || *Last == '\'' ||
- (*Last == '<' && top() == pp_include)) {
+ (*Last == '<' && (top() == pp_include || top() == pp_import))) {
if (LLVM_UNLIKELY(isRawStringLiteral(First, Last)))
skipRawString(Last, End);
else
diff --git a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
index 5fd4f6024bff34..f6ef96eaed5c05 100644
--- a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -453,6 +453,14 @@ TEST(MinimizeSourceToDependencyDirectivesTest, Include) {
ASSERT_FALSE(minimizeSourceToDependencyDirectives("#include \n", Out));
EXPECT_STREQ("#include \n", Out.data());
+ ASSERT_FALSE(
+ minimizeSourceToDependencyDirectives("#include \n", Out));
+ EXPECT_STREQ("#include \n", Out.data());
+
+ ASSERT_FALSE(
+ minimizeSourceToDependencyDirectives("#include \"A//A.h\"\n", Out));
+ EXPECT_STREQ("#include \"A//A.h\"\n", Out.data());
+
ASSERT_FALSE(
minimizeSourceToDependencyDirectives("#include_next \n", Out));
EXPECT_STREQ("#include_next \n", Out.data());
@@ -460,6 +468,13 @@ TEST(MinimizeSourceToDependencyDirectivesTest, Include) {
ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", Out));
EXPECT_STREQ("#import \n", Out.data());
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import \n", Out));
+ EXPECT_STREQ("#import \n", Out.data());
+
+ ASSERT_FALSE(
+ minimizeSourceToDependencyDirectives("#import \"A//A.h\"\n", Out));
+ EXPECT_STREQ("#import \"A//A.h\"\n", Out.data());
+
ASSERT_FALSE(
minimizeSourceToDependencyDirectives("#__include_macros \n", Out));
EXPECT_STREQ("#__include_macros \n", Out.data());