[clang] da236f2 - Strip preceeding -Xclang when stripping -fcolor-diagnostics or -fdiagnostics-color

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 26 00:11:43 PST 2020


Author: Kadir Cetinkaya
Date: 2020-02-26T09:05:05+01:00
New Revision: da236f235028c82c2f0e00eea1f6f9c689bcae4a

URL: https://github.com/llvm/llvm-project/commit/da236f235028c82c2f0e00eea1f6f9c689bcae4a
DIFF: https://github.com/llvm/llvm-project/commit/da236f235028c82c2f0e00eea1f6f9c689bcae4a.diff

LOG: Strip preceeding -Xclang when stripping -fcolor-diagnostics or -fdiagnostics-color

Summary: Fixes https://github.com/clangd/clangd/issues/279. We were removing the color options but not the preceeding -Xclang which causes errors since the -Xclang would now apply to the next option in the list of options. Now, when removing a color option, we check if there was a preceeding -Xclang and remove it as well.

Patch By @DaanDeMeyer !

Reviewers: sammccall, kadircet

Reviewed By: sammccall

Subscribers: ilya-biryukov, usaxena95

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

Added: 
    

Modified: 
    clang/lib/Tooling/ArgumentsAdjusters.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp b/clang/lib/Tooling/ArgumentsAdjusters.cpp
index 5869377a03c9..62ee954e3096 100644
--- a/clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -42,6 +42,12 @@ ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
       if (!Arg.startswith("-fcolor-diagnostics") &&
           !Arg.startswith("-fdiagnostics-color"))
         AdjustedArgs.push_back(Args[i]);
+      // If we strip a color option, make sure we strip any preceeding `-Xclang`
+      // option as well.
+      // FIXME: This should be added to most argument adjusters!
+      else if (!AdjustedArgs.empty() && AdjustedArgs.back() == "-Xclang")
+        AdjustedArgs.pop_back();
+
       if (Arg == "-fsyntax-only")
         HasSyntaxOnly = true;
     }


        


More information about the cfe-commits mailing list