···
1
+
From 7ef5ed98cc6666f64db2f155ded2077ce038e1e4 Mon Sep 17 00:00:00 2001
2
+
From: Reno Dakota <paparodeo@proton.me>
3
+
Date: Sat, 16 Nov 2024 05:57:40 +0000
4
+
Subject: [PATCH] [Clang][Driver] report unsupported option error regardless of
7
+
This change updates clang to report unsupported option errors regardless
8
+
of the command line argument order.
10
+
When clang with a source file and without `-c` it will both compile and
11
+
link. When an unsupported option is also part of the command line clang
12
+
should generated an error. However, if the source file name comes before
13
+
an object file, eg: `-lc`, the error is ignored.
16
+
$ clang --target=x86_64 -lc hello.c -mhtm
17
+
clang: error: unsupported option '-mhtm' for target 'x86_64'
22
+
but if `-lc` comes after `hello.c` the error is dropped
25
+
$ clang --target=x86_64 hello.c -mhtm -lc
30
+
after this change clang will report the error regardless of the command
31
+
line argument order.
33
+
clang/lib/Driver/Driver.cpp | 13 ++++++-------
34
+
clang/test/Driver/unsupported-option.c | 10 ++++++++++
35
+
2 files changed, 16 insertions(+), 7 deletions(-)
37
+
diff --git a/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
38
+
index 93e85f7dffe35a..8e784a7b130ac3 100644
39
+
--- a/lib/Driver/Driver.cpp
40
+
+++ b/lib/Driver/Driver.cpp
41
+
@@ -4064,17 +4064,18 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
42
+
YcArg = YuArg = nullptr;
45
+
- unsigned LastPLSize = 0;
46
+
+ bool LinkOnly = phases::Link == FinalPhase && Inputs.size() > 0;
47
+
for (auto &I : Inputs) {
48
+
types::ID InputType = I.first;
49
+
const Arg *InputArg = I.second;
51
+
auto PL = types::getCompilationPhases(InputType);
52
+
- LastPLSize = PL.size();
54
+
+ phases::ID InitialPhase = PL[0];
55
+
+ LinkOnly = LinkOnly && phases::Link == InitialPhase && PL.size() == 1;
57
+
// If the first step comes after the final phase we are doing as part of
58
+
// this compilation, warn the user about it.
59
+
- phases::ID InitialPhase = PL[0];
60
+
if (InitialPhase > FinalPhase) {
61
+
if (InputArg->isClaimed())
63
+
@@ -4129,10 +4130,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
67
+
- // If we are linking, claim any options which are obviously only used for
69
+
- // FIXME: Understand why the last Phase List length is used here.
70
+
- if (FinalPhase == phases::Link && LastPLSize == 1) {
71
+
+ // claim any options which are obviously only used for compilation.
73
+
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
74
+
Args.ClaimAllArgs(options::OPT_cl_compile_Group);