[clang] The real option name and not the alias used is displayed in msgs when using a config file (PR #107613)

Sean Perry via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 13:48:58 PDT 2024


https://github.com/perry-ca updated https://github.com/llvm/llvm-project/pull/107613

>From 27f31954976948e4e0d194db5da6bc550b4c2200 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Fri, 6 Sep 2024 10:54:07 -0500
Subject: [PATCH 1/3] clone the alias option too

---
 clang/lib/Driver/Driver.cpp          | 11 +++++++++++
 clang/test/Driver/arm-execute-only.c |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5b3783e20eabba..e4604f4e3ea753 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -998,6 +998,17 @@ static void appendOneArg(InputArgList &Args, const Arg *Opt,
   Copy->setOwnsValues(Opt->getOwnsValues());
   Opt->setOwnsValues(false);
   Args.append(Copy);
+  if (Opt->getAlias()) {
+    const Arg *Alias = Opt->getAlias();
+    unsigned Index = Args.MakeIndex(Alias->getSpelling());
+    auto AliasCopy = std::make_unique<Arg>(Alias->getOption(), Args.getArgString(Index),
+                                 Index, BaseArg);
+    AliasCopy->getValues() = Alias->getValues();
+    AliasCopy->setOwnsValues(false);
+    if (Alias->isClaimed())
+      AliasCopy->claim();
+    Copy->setAlias(std::move(AliasCopy));
+  }
 }
 
 bool Driver::readConfigFile(StringRef FileName,
diff --git a/clang/test/Driver/arm-execute-only.c b/clang/test/Driver/arm-execute-only.c
index a9bf1656fd27e5..d654ec364a87f5 100644
--- a/clang/test/Driver/arm-execute-only.c
+++ b/clang/test/Driver/arm-execute-only.c
@@ -19,6 +19,9 @@
 
 // RUN: not %clang -### --target=arm-arm-none-eabi -march=armv8-m.main -mpure-code -mno-movt %s 2>&1 \
 // RUN:    | FileCheck %s -check-prefix CHECK-PURE-CODE-NO-MOVT
+// RUN: echo "-DABC"  > %t.cfg
+// RUN: not %clang -### --target=arm-arm-none-eabi -march=armv8-m.main -mpure-code -mno-movt --config %t.cfg %s 2>&1 \
+// RUN:    | FileCheck %s -check-prefix CHECK-PURE-CODE-NO-MOVT
 // CHECK-PURE-CODE-NO-MOVT: error: option '-mpure-code' cannot be specified with '-mno-movt'
 
 // RUN: not %clang -### --target=arm-arm-none-eabi -march=armv6-m -mexecute-only -fropi %s 2>&1 \

>From 261e525859295294075bb77a1aa3bd6778d87d68 Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Fri, 6 Sep 2024 12:37:51 -0500
Subject: [PATCH 2/3] fix formatting

---
 clang/lib/Driver/Driver.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e4604f4e3ea753..5e2675db6535f1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1001,8 +1001,8 @@ static void appendOneArg(InputArgList &Args, const Arg *Opt,
   if (Opt->getAlias()) {
     const Arg *Alias = Opt->getAlias();
     unsigned Index = Args.MakeIndex(Alias->getSpelling());
-    auto AliasCopy = std::make_unique<Arg>(Alias->getOption(), Args.getArgString(Index),
-                                 Index, BaseArg);
+    auto AliasCopy = std::make_unique<Arg>(
+        Alias->getOption(), Args.getArgString(Index), Index, BaseArg);
     AliasCopy->getValues() = Alias->getValues();
     AliasCopy->setOwnsValues(false);
     if (Alias->isClaimed())

>From 12690d76b5b6906ad84bbf46d774c3c193faeb1b Mon Sep 17 00:00:00 2001
From: Sean Perry <perry at ca.ibm.com>
Date: Mon, 9 Sep 2024 15:46:34 -0500
Subject: [PATCH 3/3] Don't pass base arg to alias ctor

---
 clang/lib/Driver/Driver.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ec681943e16fa1..cbafa787354d40 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1002,7 +1002,7 @@ static void appendOneArg(InputArgList &Args, const Arg *Opt,
     const Arg *Alias = Opt->getAlias();
     unsigned Index = Args.MakeIndex(Alias->getSpelling());
     auto AliasCopy = std::make_unique<Arg>(
-        Alias->getOption(), Args.getArgString(Index), Index, BaseArg);
+        Alias->getOption(), Args.getArgString(Index), Index);
     AliasCopy->getValues() = Alias->getValues();
     AliasCopy->setOwnsValues(false);
     if (Alias->isClaimed())



More information about the cfe-commits mailing list