https://github.com/cerisier created 
https://github.com/llvm/llvm-project/pull/237563

Libclang's spelling and editor-placeholder defaults currently trigger 
unknown-argument warnings in clang-cl mode. This becomes errors under `/WX`.

Forward them through `/clang:` so valid inputs parse without these diagnostics.

@codex assisted . Human driven and reviewed.

>From 1b71664e6cea784d53231c16d0e4f1436073eb49 Mon Sep 17 00:00:00 2001
From: Corentin Kerisit <[email protected]>
Date: Sat, 31 Oct 2026 13:58:12 +0100
Subject: [PATCH] [libclang] Pass injected options through the clang-cl driver

Avoid unknown-argument diagnostics from libclang defaults in CL mode, including 
errors under /WX. Use /clang: forwarding to preserve normal driver option 
precedence.
---
 clang/test/Index/allow-editor-placeholders.cpp |  1 +
 clang/tools/libclang/CIndex.cpp                | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/clang/test/Index/allow-editor-placeholders.cpp 
b/clang/test/Index/allow-editor-placeholders.cpp
index 2870777d935c7c..f3cd63696bac13 100644
--- a/clang/test/Index/allow-editor-placeholders.cpp
+++ b/clang/test/Index/allow-editor-placeholders.cpp
@@ -1,4 +1,5 @@
 // RUN: c-index-test -test-load-source all %s 2>&1 | FileCheck %s
+// RUN: c-index-test -test-load-source all --driver-mode=cl 
--target=x86_64-pc-windows-msvc /WX %s 2>&1 | FileCheck %s
 
 <#placeholder#>;
 
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 8d246d41f31f66..cf8c24aaece327 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -39,6 +39,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/Version.h"
 #include "clang/Driver/CreateASTUnitFromArgs.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Index/CommentToXML.h"
@@ -4402,8 +4403,12 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char 
*source_filename,
   Args->insert(Args->end(), command_line_args,
                command_line_args + num_command_line_args);
 
+  // Use the driver pass-through spelling for options not accepted by clang-cl.
+  bool IsCLMode = driver::IsClangCL(
+      driver::getDriverMode((*Args)[0], llvm::ArrayRef(*Args).slice(1)));
   if (!FoundSpellCheckingArgument)
-    Args->insert(Args->begin() + 1, "-fno-spell-checking");
+    Args->insert(Args->begin() + 1, IsCLMode ? "/clang:-fno-spell-checking"
+                                             : "-fno-spell-checking");
 
   // The 'source_filename' argument is optional.  If the caller does not
   // specify it then it is assumed that the source file is specified
@@ -4420,7 +4425,8 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char 
*source_filename,
   }
 
   // Suppress any editor placeholder diagnostics.
-  Args->push_back("-fallow-editor-placeholders");
+  Args->push_back(IsCLMode ? "/clang:-fallow-editor-placeholders"
+                           : "-fallow-editor-placeholders");
 
   unsigned NumErrors = Diags->getClient()->getNumErrors();
   std::unique_ptr<ASTUnit> ErrUnit;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to