[clangd] Avoid passing -xobjective-c++-header to the system include extractor
authorNathan Ridge <zeratul976@hotmail.com>
Mon, 10 Apr 2023 05:42:20 +0000 (01:42 -0400)
committerTobias Hieta <tobias@hieta.se>
Mon, 21 Aug 2023 08:04:47 +0000 (10:04 +0200)
Fixes https://github.com/clangd/clangd/issues/1568

Differential Revision: https://reviews.llvm.org/D147905

(cherry picked from commit bd74186f1a0831b2c596e87ea056419379a223c1)

clang-tools-extra/clangd/SystemIncludeExtractor.cpp

index 4d359b0058280b1530a2f2d45e283e481831814f..8c4d9252048cdee10c0b1351232af6c764137e53 100644 (file)
@@ -136,6 +136,16 @@ struct DriverArgs {
       }
     }
 
+    // Downgrade objective-c++-header (used in clangd's fallback flags for .h
+    // files) to c++-header, as some drivers may fail to run the extraction
+    // command if it contains `-xobjective-c++-header` and objective-c++ support
+    // is not installed.
+    // In practice, we don't see different include paths for the two on
+    // clang+mac, which is the most common objectve-c compiler.
+    if (Lang == "objective-c++-header") {
+      Lang = "c++-header";
+    }
+
     // If language is not explicit in the flags, infer from the file.
     // This is important as we want to cache each language separately.
     if (Lang.empty()) {