[clang] [clang][driver] Don't warn when -S and -c are used together without -fsyntax-only (PR #104477)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 15 10:57:00 PDT 2024
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/104477
>From 0af4f441447f39df7f496e62f8620d9c8404a5d2 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 15 Aug 2024 10:52:13 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
=?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
clang/lib/Driver/Driver.cpp | 1 +
clang/test/Driver/warn-fsyntax-only.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e12416e51f8d24..0b6bc43dfebb17 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -377,6 +377,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
// -S only runs up to the backend.
} else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) {
FinalPhase = phases::Backend;
+ DAL.ClaimAllArgs(options::OPT_c);
// -c compilation only runs up to the assembler.
} else if ((PhaseArg = DAL.getLastArg(options::OPT_c))) {
diff --git a/clang/test/Driver/warn-fsyntax-only.c b/clang/test/Driver/warn-fsyntax-only.c
index d13bab41c047ad..dac6742650447f 100644
--- a/clang/test/Driver/warn-fsyntax-only.c
+++ b/clang/test/Driver/warn-fsyntax-only.c
@@ -1,7 +1,14 @@
// RUN: %clang --target=x86_64 -fsyntax-only -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-PP
// RUN: %clang --target=x86_64 -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM
// RUN: %clang --target=x86_64 -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ
+// RUN: %clang --target=x86_64 -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK-ASM,CHECK-OBJ
// CHECK-PP: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument]
// CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
+
+/// Test that -S and -c don't result in a warning, without -fsyntax-only.
+// RUN: %clang -S -c %s -### 2>&1 | FileCheck %s --check-prefix=NO-SYNTAX-ONLY --implicit-check-not=warning
+// NO-SYNTAX-ONLY: "-cc1"
+// NO-SYNTAX-ONLY-SAME: "-S"
+// NO-SYNTAX-ONLY-SAME: "c"
>From 09f10efbc79c44ec0c15c148a8c259888042f63d Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Thu, 15 Aug 2024 10:56:47 -0700
Subject: [PATCH 2/2] Add comment
Created using spr 1.3.4
---
clang/lib/Driver/Driver.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0b6bc43dfebb17..28d51eaf0104fb 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -377,6 +377,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
// -S only runs up to the backend.
} else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) {
FinalPhase = phases::Backend;
+ // Avoid unused argument warnings when combining -S and -c.
DAL.ClaimAllArgs(options::OPT_c);
// -c compilation only runs up to the assembler.
More information about the cfe-commits
mailing list