Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

In CL mode values of `/clang:` arguments end up at the end of
arguments list which makes the warning always emitted.
Just do not emit the warning in cl mode since it was implemented to
match gcc.

Fixes #59307


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142757

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/x-args.c


Index: clang/test/Driver/x-args.c
===================================================================
--- clang/test/Driver/x-args.c
+++ clang/test/Driver/x-args.c
@@ -5,3 +5,7 @@
 // RUN: %clang -fsyntax-only -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
 // RUN: %clang -fsyntax-only %s -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
 // CHECK: '-x c++' after last input file has no effect
+//
+// RUN: %clang_cl /WX /clang:-xc /clang:-E /clang:-dM %s 2>&1 | FileCheck 
-check-prefix=CL %s
+// RUN: %clang_cl /WX /clang:-E /clang:-dM %s /clang:-xc 2>&1 | FileCheck 
-check-prefix=CL %s
+// CL-NOT: '-x c' after last input file has no effect
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2572,10 +2572,11 @@
   }
 
   // Warn -x after last input file has no effect
-  {
+  if (!IsCLMode()) {
     Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
     Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
-    if (LastXArg && LastInputArg && LastInputArg->getIndex() < 
LastXArg->getIndex())
+    if (LastXArg && LastInputArg &&
+        LastInputArg->getIndex() < LastXArg->getIndex())
       Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
   }
 


Index: clang/test/Driver/x-args.c
===================================================================
--- clang/test/Driver/x-args.c
+++ clang/test/Driver/x-args.c
@@ -5,3 +5,7 @@
 // RUN: %clang -fsyntax-only -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
 // RUN: %clang -fsyntax-only %s -xc %s -xc++ -fsyntax-only 2>&1 | FileCheck %s
 // CHECK: '-x c++' after last input file has no effect
+//
+// RUN: %clang_cl /WX /clang:-xc /clang:-E /clang:-dM %s 2>&1 | FileCheck -check-prefix=CL %s
+// RUN: %clang_cl /WX /clang:-E /clang:-dM %s /clang:-xc 2>&1 | FileCheck -check-prefix=CL %s
+// CL-NOT: '-x c' after last input file has no effect
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2572,10 +2572,11 @@
   }
 
   // Warn -x after last input file has no effect
-  {
+  if (!IsCLMode()) {
     Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
     Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
-    if (LastXArg && LastInputArg && LastInputArg->getIndex() < LastXArg->getIndex())
+    if (LastXArg && LastInputArg &&
+        LastInputArg->getIndex() < LastXArg->getIndex())
       Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D142757: [cl... Mariya Podchishchaeva via Phabricator via cfe-commits

Reply via email to