[clang] [flang] [flang][draft] Improve debug info generation. (PR #84202)

2024-05-01 Thread Abid Qadeer via cfe-commits

https://github.com/abidh closed https://github.com/llvm/llvm-project/pull/84202
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [OMPIRBuilder] Don't discard the debug record from entry block. (PR #135161)

2025-04-30 Thread Abid Qadeer via cfe-commits

https://github.com/abidh closed https://github.com/llvm/llvm-project/pull/135161
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [OMPIRBuilder] Don't discard the debug record from entry block. (PR #135161)

2025-04-28 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/135161

>From 4ef791c9ad1cb951b430bff4d1ab66dd4ad30080 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 10 Apr 2025 11:32:29 +0100
Subject: [PATCH 1/3] [OMPIRBuilder] Don't discard the debug record from entry
 block.

When we get a function back from CodeExtractor, we disard its entry
block after coping its instructions into the entry block we prepared.
While copying the instructions, the terminator is discarded for obvious
reasons. But if there were some debug values attached to the terminator,
those are useful and needs to be copied.
---
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index be05f01c94603..4f3745cdd2d23 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -788,8 +788,13 @@ void OpenMPIRBuilder::finalize(Function *Fn) {
 Instruction &I = *It;
 It++;
 
-if (I.isTerminator())
+if (I.isTerminator()) {
+  // Absorb any debug value that terminator may have
+  if (OI.EntryBB->getTerminator())
+OI.EntryBB->getTerminator()->adoptDbgRecords(
+&ArtificialEntry, I.getIterator(), false);
   continue;
+}
 
 I.moveBeforePreserving(*OI.EntryBB, OI.EntryBB->getFirstInsertionPt());
   }

>From 2fff9520c56a1c6556e884478a4217f6e63d6e28 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 28 Apr 2025 13:40:32 +0100
Subject: [PATCH 2/3] Update clang test that use OMPIRBuilder for parallel
 regions.

---
 .../OpenMP/irbuilder_nested_parallel_for.c | 18 ++
 clang/test/OpenMP/nested_loop_codegen.cpp  |  4 
 clang/test/OpenMP/parallel_codegen.cpp |  2 ++
 3 files changed, 24 insertions(+)

diff --git a/clang/test/OpenMP/irbuilder_nested_parallel_for.c 
b/clang/test/OpenMP/irbuilder_nested_parallel_for.c
index ae3570fda412d..5cc5640a5173b 100644
--- a/clang/test/OpenMP/irbuilder_nested_parallel_for.c
+++ b/clang/test/OpenMP/irbuilder_nested_parallel_for.c
@@ -1679,6 +1679,9 @@ void parallel_for_2(float *r, int a, double b) {
 // CHECK-DEBUG-NEXT:[[TMP1:%.*]] = load i32, ptr [[TID_ADDR]], align 4
 // CHECK-DEBUG-NEXT:store i32 [[TMP1]], ptr [[TID_ADDR_LOCAL]], align 4
 // CHECK-DEBUG-NEXT:[[TID:%.*]] = load i32, ptr [[TID_ADDR_LOCAL]], align 4
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_A_ADDR]], 
[[META88:![0-9]+]], !DIExpression(), [[META89:![0-9]+]])
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_B_ADDR]], 
[[META90:![0-9]+]], !DIExpression(), [[META91:![0-9]+]])
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_R_ADDR]], 
[[META92:![0-9]+]], !DIExpression(), [[META93:![0-9]+]])
 // CHECK-DEBUG-NEXT:br label [[OMP_PAR_REGION:%.*]]
 // CHECK-DEBUG:   omp.par.region:
 // CHECK-DEBUG-NEXT:[[OMP_GLOBAL_THREAD_NUM1:%.*]] = call i32 
@__kmpc_global_thread_num(ptr @[[GLOB8:[0-9]+]]), !dbg [[DBG86:![0-9]+]]
@@ -1723,6 +1726,9 @@ void parallel_for_2(float *r, int a, double b) {
 // CHECK-DEBUG-NEXT:[[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON_1:%.*]], 
align 8
 // CHECK-DEBUG-NEXT:[[AGG_CAPTURED12:%.*]] = alloca [[STRUCT_ANON_2:%.*]], 
align 4
 // CHECK-DEBUG-NEXT:[[DOTCOUNT_ADDR:%.*]] = alloca i32, align 4
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_A_ADDR]], 
[[META102:![0-9]+]], !DIExpression(), [[META103:![0-9]+]])
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_B_ADDR]], 
[[META104:![0-9]+]], !DIExpression(), [[META105:![0-9]+]])
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_R_ADDR]], 
[[META106:![0-9]+]], !DIExpression(), [[META107:![0-9]+]])
 // CHECK-DEBUG-NEXT:br label [[OMP_PAR_REGION5:%.*]]
 // CHECK-DEBUG:   omp.par.region5:
 // CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[I]], [[META94:![0-9]+]], 
!DIExpression(), [[META99:![0-9]+]])
@@ -1964,6 +1970,9 @@ void parallel_for_2(float *r, int a, double b) {
 // CHECK-DEBUG-NEXT:[[AGG_CAPTURED161:%.*]] = alloca 
[[STRUCT_ANON_15:%.*]], align 8
 // CHECK-DEBUG-NEXT:[[AGG_CAPTURED162:%.*]] = alloca 
[[STRUCT_ANON_16:%.*]], align 4
 // CHECK-DEBUG-NEXT:[[DOTCOUNT_ADDR163:%.*]] = alloca i32, align 4
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_A_ADDR]], 
[[META171:![0-9]+]], !DIExpression(), [[META172:![0-9]+]])
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_B_ADDR]], 
[[META173:![0-9]+]], !DIExpression(), [[META174:![0-9]+]])
+// CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[LOADGEP_R_ADDR]], 
[[META175:![0-9]+]], !DIExpression(), [[META176:![0-9]+]])
 // CHECK-DEBUG-NEXT:br label [[OMP_PAR_REGION:%.*]]
 // CHECK-DEBUG:   omp.par.region:
 // CHECK-DEBUG-NEXT:  #dbg_declare(ptr [[I]], [[META157:![0-9]+]], 
!DIExpression(), [[META161:![0-9]+]])
@@ -2122,6 +2131,9 @@ void parallel_for_2(float *r, int a, double b) {
 // CHECK-

[clang] [llvm] [mlir] [OMPIRBuilder] Don't discard the debug record from entry block. (PR #135161)

2025-04-28 Thread Abid Qadeer via cfe-commits

abidh wrote:

We can test this functionality now as  
https://github.com/llvm/llvm-project/pull/136016 has been merged. I have added 
a test and updated relevant clang tests.

https://github.com/llvm/llvm-project/pull/135161
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [mlir] [MLIR][OpenMP] Add codegen for teams reductions (PR #133310)

2025-04-04 Thread Abid Qadeer via cfe-commits


@@ -1714,6 +1727,42 @@ convertOmpSingle(omp::SingleOp &singleOp, 
llvm::IRBuilderBase &builder,
   return success();
 }
 
+static bool teamsReductionContainedInDistribute(omp::TeamsOp teamsOp) {
+  auto iface =
+  llvm::cast(teamsOp.getOperation());
+  // Check that all uses of the reduction block arg has the same distribute op
+  // parent.
+  llvm::SmallVector debugUses;
+  Operation *distOp = nullptr;
+  for (auto ra : iface.getReductionBlockArgs())
+for (auto &use : ra.getUses()) {
+  auto *useOp = use.getOwner();
+  // Ignore debug uses.
+  if (mlir::isa(useOp)) {
+debugUses.push_back(useOp);
+continue;
+  }
+
+  auto currentDistOp = useOp->getParentOfType();
+  // Use is not inside a distribute op - return false
+  if (!currentDistOp)
+return false;
+  // Multiple distribute operations - return false
+  Operation *currentOp = currentDistOp.getOperation();
+  if (distOp && (distOp != currentOp))
+return false;
+
+  distOp = currentOp;
+}
+
+  // If we are going to use distribute reduction then remove any debug uses of
+  // the reduction parameters in teamsOp. Otherwise they will be left without
+  // any mapped value in moduleTranslation and will eventually error out.
+  for (auto use : debugUses)
+use->erase();

abidh wrote:

The `omp.distribute` has its own copy of the `hlfir.declare` for the reduction 
variable so we should not be losing this information even if we drop it from 
here.

https://github.com/llvm/llvm-project/pull/133310
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-19 Thread Abid Qadeer via cfe-commits

https://github.com/abidh created 
https://github.com/llvm/llvm-project/pull/140556

This PR add functionality to change `flang` command line using environment 
variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to what 
`CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but I am 
open to other ideas. The `applyOverrideOptions` now takes an extra argument 
that is the name of the environment variable. Previously `CCC_OVERRIDE_OPTIONS` 
was hardcoded.

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS")

[clang] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS. (PR #142396)

2025-06-02 Thread Abid Qadeer via cfe-commits

https://github.com/abidh created 
https://github.com/llvm/llvm-project/pull/142396

As was noted in 
https://github.com/llvm/llvm-project/pull/140556#discussion_r2118160690, there 
is no documentation for `CCC_OVERRIDE_OPTIONS`. This adds the missing 
documentation. The information is duplicate of what we have for 
`FCC_OVERRIDE_OPTIONS` in flang. Once this goes in and available at 
https://clang.llvm.org/docs/UsersManual.html then the flang documentation can 
be changed to refer to it.

>From b2171eec20e356d4e37920e4b6c740a3c3a4b239 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 2 Jun 2025 12:44:37 +0100
Subject: [PATCH] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS.

As was noted in 
https://github.com/llvm/llvm-project/pull/140556#discussion_r2118160690,
there is no documentation for `CCC_OVERRIDE_OPTIONS`. This adds the
missing documentation. The information is duplicate of what we have for
`FCC_OVERRIDE_OPTIONS` in flang. Once this goes in and available at
https://clang.llvm.org/docs/UsersManual.html then the flang
documentation can be changed to refer to it.
---
 clang/docs/UsersManual.rst | 29 +
 1 file changed, 29 insertions(+)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index eb9a812f0c1c9..8c72f95b94095 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3743,6 +3743,35 @@ Doxygen-style comments and ignores ordinary comments 
starting with ``//`` and
   ``-fcomment-block-commands=foo -fcomment-block-commands=bar`` does the same
   as above.
 
+.. _ccc-override-options:
+
+CCC_OVERRIDE_OPTIONS
+
+The environment variable ``CCC_OVERRIDE_OPTIONS`` can be used to edit clang's
+command line arguments. The value of this variable is a space-separated list of
+edits to perform. The edits are applied in the order in which they appear in
+``CCC_OVERRIDE_OPTIONS``. Each edit should be one of the following forms:
+
+- ``#``: Silence information about the changes to the command line arguments.
+
+- ``^FOO``: Add ``FOO`` as a new argument at the beginning of the command line
+  right after the name of the compiler executable.
+
+- ``+FOO``: Add ``FOO`` as a new argument at the end of the command line.
+
+- ``s/XXX/YYY/``: Substitute the regular expression ``XXX`` with ``YYY`` in the
+  command line.
+
+- ``xOPTION``: Removes all instances of the literal argument ``OPTION``.
+
+- ``XOPTION``: Removes all instances of the literal argument ``OPTION``, and 
the
+  following argument.
+
+- ``Ox``: Removes all flags matching ``O`` or ``O[sz0-9]`` and adds ``Ox`` at
+  the end of the command line.
+
+This environment variable does not affect the options added by the config 
files.
+
 .. _c:
 
 C Language Features

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread Abid Qadeer via cfe-commits

abidh wrote:

> I think I am seeing something similar on CI:
> 
> https://github.com/llvm/llvm-project/actions/runs/15387162550/job/43288136977?pr=140278

Thanks for reporting this. I think I will reopen it.


https://github.com/llvm/llvm-project/pull/142387
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread Abid Qadeer via cfe-commits

https://github.com/abidh reopened 
https://github.com/llvm/llvm-project/pull/142387
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS. (PR #142396)

2025-06-02 Thread Abid Qadeer via cfe-commits

abidh wrote:

The CI failure seems to be for a separate issue. I have opened 
https://github.com/llvm/llvm-project/pull/142387 for it.

https://github.com/llvm/llvm-project/pull/142396
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-02 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/9] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-02 Thread Abid Qadeer via cfe-commits

abidh wrote:

The test failure in Lower/namelist.f90 was due to `CHECK-NOT: bbb` while `bbb` 
can appeared in compiler generated variable name so unrelated to this change. 
Opened https://github.com/llvm/llvm-project/pull/142363 to harden that testcase.

https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread Abid Qadeer via cfe-commits

https://github.com/abidh closed https://github.com/llvm/llvm-project/pull/142387
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread Abid Qadeer via cfe-commits

abidh wrote:

I see that 
https://clang.llvm.org/docs/DiagnosticsReference.html#wunique-object-duplication
 is showing this correctly without this PR so problem may be something local to 
my machine. Closing it for now.

https://github.com/llvm/llvm-project/pull/142387
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-29 Thread Abid Qadeer via cfe-commits


@@ -614,3 +614,28 @@ nvfortran defines `-fast` as
  - `-Mcache_align`: there is no equivalent flag in Flang or Clang.
  - `-Mflushz`: flush-to-zero mode - when `-ffast-math` is specified, Flang will
link to `crtfastmath.o` to ensure denormal numbers are flushed to zero.
+
+
+## FCC_OVERRIDE_OPTIONS
+
+The environment variable `FCC_OVERRIDE_OPTIONS` can be used to apply a list of
+edits to the input argument lists. The value of this environment variable is

abidh wrote:

It does not effect the options added by the configuration files. The behavior 
is consistent with clang and `CCC_OVERRIDE_OPTIONS`.  I added a line in the 
documentation for it.

https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-29 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/3] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-29 Thread Abid Qadeer via cfe-commits


@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s

abidh wrote:

Yes, those have special meaning and they were only documented in the comments. 
I have now added documentation for it in the suggested file.

https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-29 Thread Abid Qadeer via cfe-commits

abidh wrote:

> Does `CCC_OVERRIDE_OPTIONS` expands to Clang Compiler Commandline Override 
> Options? If so `FCC_OVERRIDE_OPTIONS` expanding to Fortran Compiler 
> Commandline Override Options seems the right replacement.
> 
> If `CCC_OVERRIDE_OPTIONS` expands to Clang C Compiler Override Options then 
> `FFC_OVERRIDE_OPTIONS` (as suggested by @tarunprabhu) expanding to Flang 
> Fortran Compiler Overrided Options is better.

The `CCC_OVERRIDE_OPTIONS` was introduced in a19fad as replacement of 
`QA_OVERRIDE_GCC3_OPTIONS`.  I am not sure if there is a definite word on what 
it actually expands to. I am happy with either of them.


https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-29 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/2] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-01 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/8] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-01 Thread Abid Qadeer via cfe-commits


@@ -614,3 +614,30 @@ nvfortran defines `-fast` as
  - `-Mcache_align`: there is no equivalent flag in Flang or Clang.
  - `-Mflushz`: flush-to-zero mode - when `-ffast-math` is specified, Flang will
link to `crtfastmath.o` to ensure denormal numbers are flushed to zero.
+
+
+## FCC_OVERRIDE_OPTIONS
+
+The environment variable `FCC_OVERRIDE_OPTIONS` can be used to edit flang's
+command line arguments. The value of this variable is a space-separated list of
+edits to perform. The edits are applied in the order in which they appear in
+`FCC_OVERRIDE_OPTIONS`. Each edit should be one of the following forms:
+
+- `#`: Silence information about the changes to the command line arguments.
+
+- `^FOO`: Add `FOO` as a new argument at the beginning of the command line.

abidh wrote:

I have added "right after the name of the compiler executable" in both places. 
Hopefully that is enough to make it clear.

https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-01 Thread Abid Qadeer via cfe-commits


@@ -614,3 +614,30 @@ nvfortran defines `-fast` as
  - `-Mcache_align`: there is no equivalent flag in Flang or Clang.
  - `-Mflushz`: flush-to-zero mode - when `-ffast-math` is specified, Flang will
link to `crtfastmath.o` to ensure denormal numbers are flushed to zero.
+
+
+## FCC_OVERRIDE_OPTIONS

abidh wrote:

I will add clang documentation in a separate PR. The `FCC_OVERRIDE_OPTIONS` one 
can then probably just refer to it.

https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Add docs for CCC_OVERRIDE_OPTIONS. (PR #142396)

2025-06-03 Thread Abid Qadeer via cfe-commits

https://github.com/abidh closed https://github.com/llvm/llvm-project/pull/142396
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][docs] Fix docs-clang-html. (PR #142387)

2025-06-02 Thread Abid Qadeer via cfe-commits

https://github.com/abidh created 
https://github.com/llvm/llvm-project/pull/142387

I observed that docs-clang-html is failing since 
https://github.com/llvm/llvm-project/pull/142158 with the following:

Warning, treated as error:
tools/clang/docs/DiagnosticsReference.rst:18000:Unexpected indentation. ninja: 
build stopped: subcommand failed.

Adding an extra empty line here fixes the build.

>From b225852be24bf300e3841052856af795bcb897ed Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 2 Jun 2025 14:03:29 +0100
Subject: [PATCH] [clang][docs] Fix docs-clang-html.

I observed that docs-clang-html is failing since 
https://github.com/llvm/llvm-project/pull/142158,

Warning, treated as error:
tools/clang/docs/DiagnosticsReference.rst:18000:Unexpected indentation.
ninja: build stopped: subcommand failed.

Adding an extra empty line here fixes the build.
---
 clang/include/clang/Basic/DiagnosticGroups.td | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 60c650583801a..0161b3953f282 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -821,6 +821,7 @@ As well as one of the following:
 
 The warning can be resolved by removing one of the conditions above. In rough
 order of preference, this may be done by:
+
   1. Marking the object ``const`` (if possible)
   2. Moving the object's definition to a source file
   3. Giving the object non-hidden visibility, e.g. using 
``__attribute((visibility("default")))``.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] Tweak docs for unique-object-duplication warning (PR #142158)

2025-06-02 Thread Abid Qadeer via cfe-commits

abidh wrote:

I noticed docs-clang-html failing after this. I have opened 
https://github.com/llvm/llvm-project/pull/142387 to fix it.

https://github.com/llvm/llvm-project/pull/142158
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-02 Thread Abid Qadeer via cfe-commits

https://github.com/abidh closed https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-30 Thread Abid Qadeer via cfe-commits


@@ -614,3 +614,30 @@ nvfortran defines `-fast` as
  - `-Mcache_align`: there is no equivalent flag in Flang or Clang.
  - `-Mflushz`: flush-to-zero mode - when `-ffast-math` is specified, Flang will
link to `crtfastmath.o` to ensure denormal numbers are flushed to zero.
+
+
+## FCC_OVERRIDE_OPTIONS
+
+The environment variable `FCC_OVERRIDE_OPTIONS` can be used to apply a list of
+edits to the input argument lists. The value of this environment variable is
+a space separated list of edits to perform. These edits are applied in order to
+the input argument lists. Edits should be one of the following forms:

abidh wrote:

Thanks. This looks better than what I had originally. I have updated the docs.

https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-30 Thread Abid Qadeer via cfe-commits


@@ -0,0 +1,17 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s

abidh wrote:

Indeed. Thanks for catching this. Fixed now.

https://github.com/llvm/llvm-project/pull/140556
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-30 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/7] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-30 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/5] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-05-30 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/6] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [llvm] [IRBuilder] Improve setting of DebugLoc in SetInsertPoint. (PR #147091)

2025-07-04 Thread Abid Qadeer via cfe-commits

https://github.com/abidh created 
https://github.com/llvm/llvm-project/pull/147091

Currently, in `SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP)` if 
the `IP` is pointing to the end of the `TheBB`, the debugLoc is not changed 
although the insertion point now points to a different location. This has been 
source of many problems in the `OMPIRBuilder`.

In `OMPIRBuilder`, the following code pattern is quite common.

```
  auto OldIP = Builder.saveIP();
  Builder.SetInsertPoint(/* some new location */);
  // Generate some code.
  Builder.restoreIP(OldIP);

```
An example can be seen 
[here](https://github.com/llvm/llvm-project/blob/b0473c599b0418c71d15150e0ea19d57df3b98e5/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp#L1869).
 If the `OldIP` is pointing to the end of the `BasicBlock`, `SetInsertPoint` 
will not call `SetCurrentDebugLocation` and we have a mismatch between 
InsertPoint and the DebugLoc. This causes many subtle bugs like 
[147063](https://github.com/llvm/llvm-project/issues/147063).

I fixed it by by using the debug location of the last instruction in the 
`BasicBlock` if the `InsertPoint` is at the end. Some clang OpenMP tests needed 
minor adjustments to work with this change.

Fixes #147063.

>From 22d9b3a8fbcc74a4f9559df16918fc1c4814da49 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Tue, 1 Jul 2025 22:17:26 +0100
Subject: [PATCH] [IRBuilder] Improve setting of DebugLoc in SetInsertPoint.

Currently, in SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP)
if the IP is pointing to the end of the TheBB, the debugLoc is not
changed although the insertion point now points to a different location.
This has been source of many problems in the OMPIRBuilder.

In OMPIRBuilder, the following code pattern is quite common.

  auto OldIP = Builder.saveIP();
  Builder.SetInsertPoint(/* some new location */);
  // Generate some code.
  Builder.restoreIP(OldIP);

An example can be seen here. If the OldIP is pointing to the end of the
BasicBlock, SetInsertPoint will not call setCurrentDebugLocation(). This
causes many subtle bugs like this.

I fixed it by by using the debug location of the last instruction in the
BasicBlock if the InsertPoint is at the end. Some clang OpenMP tests
needed minor adjustments to work with this change.

Fixes #147063.
---
 clang/test/OpenMP/parallel_codegen.cpp | 10 +++
 clang/test/OpenMP/parallel_for_codegen.cpp |  4 +--
 clang/test/OpenMP/scope_codegen.cpp|  4 +--
 clang/test/OpenMP/taskgroup_codegen.cpp|  8 +++---
 llvm/include/llvm/IR/IRBuilder.h   |  2 ++
 llvm/unittests/IR/IRBuilderTest.cpp| 33 ++
 6 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/clang/test/OpenMP/parallel_codegen.cpp 
b/clang/test/OpenMP/parallel_codegen.cpp
index e8e57aedaa164..6be8ff5149f2a 100644
--- a/clang/test/OpenMP/parallel_codegen.cpp
+++ b/clang/test/OpenMP/parallel_codegen.cpp
@@ -354,7 +354,7 @@ int main (int argc, char **argv) {
 // CHECK2-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr 
[[TMP1]], i64 1, !dbg [[DBG54:![0-9]+]]
 // CHECK2-NEXT:[[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !dbg 
[[DBG54]]
 // CHECK2-NEXT:invoke void @_Z3fooIiEvT_(i32 noundef [[TMP2]])
-// CHECK2-NEXT:to label [[INVOKE_CONT:%.*]] unwind label 
[[TERMINATE_LPAD:%.*]], !dbg [[DBG53]]
+// CHECK2-NEXT:to label [[INVOKE_CONT:%.*]] unwind label 
[[TERMINATE_LPAD:%.*]], !dbg [[DBG54]]
 // CHECK2:   invoke.cont:
 // CHECK2-NEXT:[[TMP3:%.*]] = load i32, ptr @global, align 4, !dbg 
[[DBG55:![0-9]+]]
 // CHECK2-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP1]], i64 1, !dbg [[DBG56:![0-9]+]]
@@ -480,7 +480,7 @@ int main (int argc, char **argv) {
 // CHECK2-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr 
[[TMP1]], i64 1, !dbg [[DBG107:![0-9]+]]
 // CHECK2-NEXT:[[TMP3:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !dbg 
[[DBG107]]
 // CHECK2-NEXT:invoke void @_Z3fooIiEvT_(i32 noundef [[TMP3]])
-// CHECK2-NEXT:to label [[INVOKE_CONT:%.*]] unwind label 
[[TERMINATE_LPAD:%.*]], !dbg [[DBG106]]
+// CHECK2-NEXT:to label [[INVOKE_CONT:%.*]] unwind label 
[[TERMINATE_LPAD:%.*]], !dbg [[DBG107]]
 // CHECK2:   invoke.cont:
 // CHECK2-NEXT:[[TMP4:%.*]] = load i32, ptr [[TMP2]], align 4, !dbg 
[[DBG108:![0-9]+]]
 // CHECK2-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr 
[[TMP1]], i64 1, !dbg [[DBG109:![0-9]+]]
@@ -588,7 +588,7 @@ int main (int argc, char **argv) {
 // CHECK2-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr 
[[TMP1]], i64 1, !dbg [[DBG143:![0-9]+]]
 // CHECK2-NEXT:[[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !dbg 
[[DBG143]]
 // CHECK2-NEXT:invoke void @_Z3fooIiEvT_(i32 noundef [[TMP2]])
-// CHECK2-NEXT:to label [[INVOKE_CONT:%.*]] unwind label 
[[TERMINATE_LPAD:%.*]], !dbg [[DBG142]]
+// CHECK2-NEXT:to label [[INVOKE_CONT:%.*]] unwind label

[clang] [llvm] [IRBuilder] Improve setting of DebugLoc in SetInsertPoint. (PR #147091)

2025-07-11 Thread Abid Qadeer via cfe-commits

abidh wrote:

Polite ping.

https://github.com/llvm/llvm-project/pull/147091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IRBuilder] Improve setting of DebugLoc in SetInsertPoint. (PR #147091)

2025-07-18 Thread Abid Qadeer via cfe-commits

abidh wrote:

> I'm not sure I agree with the principle of this change; the current behaviour 
> of not getting a DebugLoc when setting the insertion point to the end of a 
> BasicBlock is long-standing and this change might have unexpected knock-on 
> effects (although if we do make this change, it must also be extended to the 
> `setInsertPoint(BasicBlock*)` version of this function to avoid a confusing 
> difference). I think the more reasonable version of this change would be to 
> save and restore the old debug location explicitly - the RAII version of this 
> pattern, `llvm::InsertPointGuard`, has this behaviour. Updating the 
> `InsertPoint` class and every consumer of its API would be onerous, but has 
> less risk of introducing surprising results; modifying just the code that 
> causes #147063 to save and restore a debug location would be preferable to 
> this, at least imo. I'm open to changing my mind if there's a good argument 
> that this behaviour is correct in principle, however.

Thanks @SLTozer for your comments. I started fixing the individual cases which 
cause #147063 but then thought that it may be good to fix the problem in more 
general sense. Although I think the current behavior is not the right one but I 
do agree that it is long standing one and there may be dependency on this 
behavior in the clients. On the positive side, the adjustments required in 
testcases were quite small which indicates that dependency on this behavior may 
not be very deep (and the debug location in those testcases after this change 
look better imho).

The rationale for change was that if we are inserting at the end of a BB, the 
`DebugLoc` of the last instruction in that BB is better match then the 
`DebugLoc` of a random BB (which is some cases may not even be in the same 
function). May be the problem is absence of `DebugLoc` in `InsertPoint` which 
requires us to guess `DebugLoc` to use instead of it being part of 
`InsertPoint` like it is for `llvm::InsertPointGuard`.

https://github.com/llvm/llvm-project/pull/147091
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] 380fee3 - [libunwind] Provide a way to set '_LIBUNWIND_IS_BAREMETAL' through cmake.

2020-07-29 Thread Hafiz Abid Qadeer via cfe-commits

Author: Hafiz Abid Qadeer
Date: 2020-07-29T11:48:28+01:00
New Revision: 380fee34d2794361f9e222fe3c8c065be3b9fff8

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

LOG: [libunwind] Provide a way to set '_LIBUNWIND_IS_BAREMETAL' through cmake.

Libunwind uses _LIBUNWIND_IS_BAREMETAL in a lot of places but there is no cmake 
variable to set it. This patch adds such a variable. It is quite like what 
LIBCXXABI_BAREMETAL does in libcxxabi.

Reviewed By: compnerd, #libunwind

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

Added: 


Modified: 
libunwind/CMakeLists.txt

Removed: 




diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index c5b536532f3c..4606360f07ab 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -137,6 +137,7 @@ option(LIBUNWIND_ENABLE_THREADS "Build libunwind with 
threading support." ON)
 option(LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread 
functions." OFF)
 option(LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
 option(LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." 
${LLVM_INCLUDE_DOCS})
+option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
@@ -361,6 +362,10 @@ if (LIBUNWIND_ENABLE_ARM_WMMX)
   add_compile_flags(-D__ARM_WMMX)
 endif()
 
+if(LIBUNWIND_IS_BAREMETAL)
+  add_compile_definitions(_LIBUNWIND_IS_BAREMETAL)
+endif()
+
 # This is the _ONLY_ place where add_definitions is called.
 if (MSVC)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 670686a - Add initial support for multilibs in Baremetal toolchain.

2020-12-14 Thread Hafiz Abid Qadeer via cfe-commits

Author: Hafiz Abid Qadeer
Date: 2020-12-14T20:49:45Z
New Revision: 670686ad8ecc80158a6ff87fff55e0ffa6fdff5d

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

LOG: Add initial support for multilibs in Baremetal toolchain.

This patch add support of riscv multilibs in the Baremetal toolchain. It is
a bit different to what is done in GNU.cpp as we are not iterating a
GNU sysroot to find the multilibs. This is intended for an llvm only
toolchain. We are not checking for the presence of any runtime bits to
enable a specific multilib.

I have structured the patch so that other targets for which
there is no multilibs support yet in Baremetal.cpp (e.g. arm-none-eabi)
will not be affected. Patch also allows some multilibs reuse.

Long term, I would like to go in the direction of data-driven specification of
multilib directories and flags.

Reviewed By: jroelofs

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/BareMetal.h
clang/test/Driver/baremetal.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 7429c822b7e9..7619dd30da5a 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -12,6 +12,7 @@
 #include "InputInfo.h"
 #include "Gnu.h"
 
+#include "Arch/RISCV.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -27,12 +28,77 @@ using namespace clang::driver;
 using namespace clang::driver::tools;
 using namespace clang::driver::toolchains;
 
+static Multilib makeMultilib(StringRef commonSuffix) {
+  return Multilib(commonSuffix, commonSuffix, commonSuffix);
+}
+
+static bool findRISCVMultilibs(const Driver &D,
+   const llvm::Triple &TargetTriple,
+   const ArgList &Args, DetectedMultilibs &Result) 
{
+  Multilib::flags_list Flags;
+  StringRef Arch = riscv::getRISCVArch(Args, TargetTriple);
+  StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple);
+
+  if (TargetTriple.getArch() == llvm::Triple::riscv64) {
+Multilib Imac = 
makeMultilib("").flag("+march=rv64imac").flag("+mabi=lp64");
+Multilib Imafdc = makeMultilib("/rv64imafdc/lp64d")
+  .flag("+march=rv64imafdc")
+  .flag("+mabi=lp64d");
+
+// Multilib reuse
+bool UseImafdc =
+(Arch == "rv64imafdc") || (Arch == "rv64gc"); // gc => imafdc
+
+addMultilibFlag((Arch == "rv64imac"), "march=rv64imac", Flags);
+addMultilibFlag(UseImafdc, "march=rv64imafdc", Flags);
+addMultilibFlag(Abi == "lp64", "mabi=lp64", Flags);
+addMultilibFlag(Abi == "lp64d", "mabi=lp64d", Flags);
+
+Result.Multilibs = MultilibSet().Either(Imac, Imafdc);
+return Result.Multilibs.select(Flags, Result.SelectedMultilib);
+  }
+  if (TargetTriple.getArch() == llvm::Triple::riscv32) {
+Multilib Imac =
+makeMultilib("").flag("+march=rv32imac").flag("+mabi=ilp32");
+Multilib I =
+makeMultilib("/rv32i/ilp32").flag("+march=rv32i").flag("+mabi=ilp32");
+Multilib Im =
+
makeMultilib("/rv32im/ilp32").flag("+march=rv32im").flag("+mabi=ilp32");
+Multilib Iac = makeMultilib("/rv32iac/ilp32")
+   .flag("+march=rv32iac")
+   .flag("+mabi=ilp32");
+Multilib Imafc = makeMultilib("/rv32imafc/ilp32f")
+ .flag("+march=rv32imafc")
+ .flag("+mabi=ilp32f");
+
+// Multilib reuse
+bool UseI = (Arch == "rv32i") || (Arch == "rv32ic");// ic => i
+bool UseIm = (Arch == "rv32im") || (Arch == "rv32imc"); // imc => im
+bool UseImafc = (Arch == "rv32imafc") || (Arch == "rv32imafdc") ||
+(Arch == "rv32gc"); // imafdc,gc => imafc
+
+addMultilibFlag(UseI, "march=rv32i", Flags);
+addMultilibFlag(UseIm, "march=rv32im", Flags);
+addMultilibFlag((Arch == "rv32iac"), "march=rv32iac", Flags);
+addMultilibFlag((Arch == "rv32imac"), "march=rv32imac", Flags);
+addMultilibFlag(UseImafc, "march=rv32imafc", Flags);
+addMultilibFlag(Abi == "ilp32", "mabi=ilp32", Flags);
+addMultilibFlag(Abi == "ilp32f", "mabi=ilp32f", Flags);
+
+Result.Multilibs = MultilibSet().Either(I, Im, Iac, Imac, Imafc);
+return Result.Multilibs.select(Flags, Result.SelectedMultilib);
+  }
+  return false;
+}
+
 BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
 : ToolChain(D, Triple, Args) {
   getProgramPaths().push_back(getDriver().getInstalledDir());
   if (getDriver().getInstalledDir() != getDriver().Dir)
 getP

[clang] 8cdc538 - Add sysroot/lib to library search path of baremetal toolchain.

2020-11-18 Thread Hafiz Abid Qadeer via cfe-commits

Author: Hafiz Abid Qadeer
Date: 2020-11-18T12:38:52Z
New Revision: 8cdc538873879bd57c3ba71956d68b49a2973a45

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

LOG: Add sysroot/lib to library search path of baremetal toolchain.

Baremetal toolchain is not adding sysroot/lib to the library
search path. This is forcing the user to do it manually. This commit
fixes this shortcoming by adding the sysroot/lib to library search path
if sysroot is not empty.

Reviewed By: jroelofs

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/baremetal.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 9df42061e12c..91e2715404fe 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -33,6 +33,11 @@ BareMetal::BareMetal(const Driver &D, const llvm::Triple 
&Triple,
   getProgramPaths().push_back(getDriver().getInstalledDir());
   if (getDriver().getInstalledDir() != getDriver().Dir)
 getProgramPaths().push_back(getDriver().Dir);
+  SmallString<128> SysRoot(getDriver().SysRoot);
+  if (!SysRoot.empty()) {
+llvm::sys::path::append(SysRoot, "lib");
+getFilePaths().push_back(std::string(SysRoot));
+  }
 }
 
 /// Is the triple {arm,thumb}-none-none-{eabi,eabihf} ?
@@ -189,6 +194,7 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   CmdArgs.push_back(Args.MakeArgString("-L" + TC.getRuntimesDir()));
 
+  TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.AddAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_e, options::OPT_s, options::OPT_t,
 options::OPT_Z_Flag, options::OPT_r});

diff  --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index 3a5c1555dc2c..f9d48e46e639 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -12,6 +12,7 @@
 // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
 // CHECK-V6M-C-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-C-SAME: "-o" "{{.*}}.o"
@@ -34,6 +35,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-DEFAULTCXX %s
 // CHECK-V6M-DEFAULTCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-DEFAULTCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-DEFAULTCXX-SAME: "-o" "{{.*}}.o"
@@ -47,6 +49,7 @@
 // CHECK-V6M-LIBCXX: "-internal-isystem" 
"{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECK-V6M-LIBCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-LIBCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
 // CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o"
@@ -60,6 +63,7 @@
 // CHECK-V6M-LIBSTDCXX: "-internal-isystem" 
"{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}6.0.0"
 // CHECK-V6M-LIBSTDCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
 // CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-LIBSTDCXX-SAME: 
"-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-LIBSTDCXX-SAME: "-o" "{{.*}}.o"
@@ -70,7 +74,8 @@
 // RUN: -nodefaultlibs \
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-NDL %s
 // CHECK-V6M-NDL: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" 
"-Bstatic"
-// CHECK-V6M-NDL-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal"
 "-o" "{{.*}}.o"
+// CHECK-V6M-NDL-SAME: 
"-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\

[clang] 45ba239 - [clang][Driver] Handle risvc in Baremetal.cpp.

2020-11-26 Thread Hafiz Abid Qadeer via cfe-commits

Author: Hafiz Abid Qadeer
Date: 2020-11-26T11:43:17Z
New Revision: 45ba2392d7e00aedd4d9fb04070dbae8a7fbbeeb

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

LOG: [clang][Driver] Handle risvc in Baremetal.cpp.

I am working on a baremetal riscv toolchain using LLVM runtime and
LLD linker. Baremetal.cpp provides most of the things needed for such
toolchain. So I have modified it to also handle riscv64/32-unknown-elf
 targets alongside arm-none-eabi.

Currently, targets like riscv64-unknown-elf are handled by RISCVToolChain
which mostly expects a gcc toolchain to be present. If you dont
want the dependency on gcc-toolchain/libgloss or want to use LLD, then
RISCVToolChain is not a good fit.

So in the toolchain selection code, I have made this dependency of
RISCVToolChain on gcc toolchain explicit. It is created if gcc-toolchain
option is present. Otherwise Baremetal toolchain is created. I will be
happy to hear if there is a better way to choose between these two
toolchains.

Reviewed By: jroelofs

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.h
clang/test/Driver/baremetal.cpp
clang/test/Driver/riscv-gnutools.c
clang/test/Driver/riscv32-toolchain-extra.c
clang/test/Driver/riscv32-toolchain.c
clang/test/Driver/riscv64-toolchain-extra.c
clang/test/Driver/riscv64-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index fb258197cfdd..5e4eb8c4e6c5 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5213,7 +5213,11 @@ const ToolChain &Driver::getToolChain(const ArgList 
&Args,
 break;
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-TC = std::make_unique(*this, Target, Args);
+if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args))
+  TC =
+  std::make_unique(*this, Target, 
Args);
+else
+  TC = std::make_unique(*this, Target, Args);
 break;
   case llvm::Triple::ve:
 TC = std::make_unique(*this, Target, Args);

diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 91e2715404fe..e032d07112eb 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -59,8 +59,22 @@ static bool isARMBareMetal(const llvm::Triple &Triple) {
   return true;
 }
 
+static bool isRISCVBareMetal(const llvm::Triple &Triple) {
+  if (Triple.getArch() != llvm::Triple::riscv32 &&
+  Triple.getArch() != llvm::Triple::riscv64)
+return false;
+
+  if (Triple.getVendor() != llvm::Triple::UnknownVendor)
+return false;
+
+  if (Triple.getOS() != llvm::Triple::UnknownOS)
+return false;
+
+  return Triple.getEnvironmentName() == "elf";
+}
+
 bool BareMetal::handlesTarget(const llvm::Triple &Triple) {
-  return isARMBareMetal(Triple);
+  return isARMBareMetal(Triple) || isRISCVBareMetal(Triple);
 }
 
 Tool *BareMetal::buildLinker() const {

diff  --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 312c8b52c5e8..0dc12c7a84b5 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -31,6 +31,21 @@ static void addMultilibsFilePaths(const Driver &D, const 
MultilibSet &Multilibs,
   addPathIfExists(D, InstallPath + Path, Paths);
 }
 
+// This function tests whether a gcc installation is present either
+// through gcc-toolchain argument or in the same prefix where clang
+// is installed. This helps decide whether to instantiate this toolchain
+// or Baremetal toolchain.
+bool RISCVToolChain::hasGCCToolchain(const Driver &D,
+ const llvm::opt::ArgList &Args) {
+  if (Args.getLastArg(options::OPT_gcc_toolchain))
+return true;
+
+  SmallString<128> GCCDir;
+  llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(),
+  "lib/crt0.o");
+  return llvm::sys::fs::exists(GCCDir);
+}
+
 /// RISCV Toolchain
 RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)

diff  --git a/clang/lib/Driver/ToolChains/RISCVToolchain.h 
b/clang/lib/Driver/ToolChains/RISCVToolchain.h
index 4734aee5f1ab..62099bee0404 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.h
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.h
@@ -21,6 +21,7 @@ class LLVM_LIBRARY_VISIBILITY RISCVToolChain : public 
Generic_ELF {
   RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
 

[clang] ca28883 - Don't use sysroot/include when sysroot is empty.

2020-12-04 Thread Hafiz Abid Qadeer via cfe-commits

Author: Hafiz Abid Qadeer
Date: 2020-12-04T18:33:24Z
New Revision: ca2888310b245d0532d989685a090ae373ee3f93

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

LOG: Don't use sysroot/include when sysroot is empty.

Baremetal toolchain add Driver.SysRoot/include to the system include
paths without checking if Driver.SysRoot is empty. This resulted in
"-internal-isystem" "include" in the command. This patch adds check for
empty sysroot.

Reviewed By: jroelofs

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/test/Driver/baremetal.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index e032d07112eb..20ffd4b2cd57 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -107,8 +107,10 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
 
   if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
 SmallString<128> Dir(getDriver().SysRoot);
-llvm::sys::path::append(Dir, "include");
-addSystemInclude(DriverArgs, CC1Args, Dir.str());
+if (!Dir.empty()) {
+  llvm::sys::path::append(Dir, "include");
+  addSystemInclude(DriverArgs, CC1Args, Dir.str());
+}
   }
 }
 

diff  --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index 7dd213ee56b4..addf09f00e14 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -93,6 +93,10 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-RTLIB-GCC
 // CHECK-RTLIB-GCC: -lgcc
 
+// RUN: %clang -### -target arm-none-eabi -v %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-SYSROOT-INC
+// CHECK-SYSROOT-INC-NOT: "-internal-isystem" "include"
+
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target riscv64-unknown-elf \
 // RUN: -L some/directory/user/asked/for \



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 275592e - Provide default location of sysroot for Baremetal toolchain.

2020-12-07 Thread Hafiz Abid Qadeer via cfe-commits

Author: Hafiz Abid Qadeer
Date: 2020-12-07T09:19:52Z
New Revision: 275592e714130345a481a5cb889c89b73a98614f

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

LOG: Provide default location of sysroot for Baremetal  toolchain.

Currently, Baremetal toolchain requires user to pass a sysroot location
using a --sysroot flag. This is not very convenient for the user. It also
creates problem for toolchain vendors who don't have a fixed location to
put the sysroot bits.

Clang does provide 'DEFAULT_SYSROOT' which can be used by the toolchain
builder to provide the default location. But it does not work if toolchain
is targeting multiple targets e.g. arm-none-eabi/riscv64-unknown-elf which
clang is capable of doing.

This patch tries to solve this problem by providing a default location of
the toolchain if user does not explicitly provides --sysroot. The exact
location and name can be different but it should fulfill these conditions:

1. The sysroot path should have a target triple element so that multi-target
toolchain problem (as I described above) could be addressed.

2. The location should not be $TOP/$Triple as this is used by gcc generally
and will be a problem for installing both gcc and clang based toolchain at
the same location.

Reviewed By: jroelofs

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

Added: 
clang/test/Driver/baremetal-sysroot.cpp

Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/BareMetal.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 20ffd4b2cd57..7429c822b7e9 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -33,7 +33,7 @@ BareMetal::BareMetal(const Driver &D, const llvm::Triple 
&Triple,
   getProgramPaths().push_back(getDriver().getInstalledDir());
   if (getDriver().getInstalledDir() != getDriver().Dir)
 getProgramPaths().push_back(getDriver().Dir);
-  SmallString<128> SysRoot(getDriver().SysRoot);
+  SmallString<128> SysRoot(computeSysRoot());
   if (!SysRoot.empty()) {
 llvm::sys::path::append(SysRoot, "lib");
 getFilePaths().push_back(std::string(SysRoot));
@@ -94,6 +94,17 @@ std::string BareMetal::getRuntimesDir() const {
   return std::string(Dir.str());
 }
 
+std::string BareMetal::computeSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  SmallString<128> SysRootDir;
+  llvm::sys::path::append(SysRootDir, getDriver().Dir, "../lib/clang-runtimes",
+  getDriver().getTargetTriple());
+
+  return std::string(SysRootDir);
+}
+
 void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
   ArgStringList &CC1Args) const {
   if (DriverArgs.hasArg(options::OPT_nostdinc))
@@ -106,7 +117,7 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList 
&DriverArgs,
   }
 
   if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
-SmallString<128> Dir(getDriver().SysRoot);
+SmallString<128> Dir(computeSysRoot());
 if (!Dir.empty()) {
   llvm::sys::path::append(Dir, "include");
   addSystemInclude(DriverArgs, CC1Args, Dir.str());
@@ -127,7 +138,7 @@ void BareMetal::AddClangCXXStdlibIncludeArgs(
   DriverArgs.hasArg(options::OPT_nostdincxx))
 return;
 
-  StringRef SysRoot = getDriver().SysRoot;
+  std::string SysRoot(computeSysRoot());
   if (SysRoot.empty())
 return;
 

diff  --git a/clang/lib/Driver/ToolChains/BareMetal.h 
b/clang/lib/Driver/ToolChains/BareMetal.h
index 0be9377134ce..3f4fadf8a7c3 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.h
+++ b/clang/lib/Driver/ToolChains/BareMetal.h
@@ -67,6 +67,7 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
llvm::opt::ArgStringList &CmdArgs) const override;
   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
  llvm::opt::ArgStringList &CmdArgs) const;
+  std::string computeSysRoot() const override;
 };
 
 } // namespace toolchains

diff  --git a/clang/test/Driver/baremetal-sysroot.cpp 
b/clang/test/Driver/baremetal-sysroot.cpp
new file mode 100644
index ..ae174e01417e
--- /dev/null
+++ b/clang/test/Driver/baremetal-sysroot.cpp
@@ -0,0 +1,22 @@
+// REQUIRES: shell
+// UNSUPPORTED: system-windows
+
+// Test that when a --sysroot is not provided, driver picks the default
+// location correctly if available.
+
+// RUN: rm -rf %T/baremetal_default_sysroot
+// RUN: mkdir -p %T/baremetal_default_sysroot/bin
+// RUN: mkdir -p 
%T/baremetal_default_sysroot/lib/clang-runtimes/armv6m-none-eabi
+// RUN: ln -s %clang %T/baremetal_default_sysroot/bin/clang
+
+// RUN: %T/baremetal_default_sysroot/bin/clang -no-canonica

[clang] 60bed4a - Replace deprecated %T in 2 tests.

2021-02-11 Thread Hafiz Abid Qadeer via cfe-commits

Author: Hafiz Abid Qadeer
Date: 2021-02-11T22:21:21Z
New Revision: 60bed4ab57d562d5770cc9c24a8fcb243208f5e5

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

LOG: Replace deprecated %T in 2 tests.

In D91442, @MaskRay commented about a failure. This commit does the following to
address his comments:

1. Replace %T with %t as former is deprecated.
2. Add an explicit --sysroot argument in a test.

Some tests were failing when gcc-10-riscv64-linux-gnu is installed on test 
machine.
This was happening because the test was checking a case when --gcc-toolchain is 
not
provided. But if --sysroot was also not provided then code could pick a 
toolchain
installed in /usr. So to make the test more robust, I have provided an explicit 
--sysroot
argument. Its value has been chosen to match the existing patterns.

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/test/Driver/riscv32-toolchain-extra.c
clang/test/Driver/riscv64-toolchain-extra.c

Removed: 




diff  --git a/clang/test/Driver/riscv32-toolchain-extra.c 
b/clang/test/Driver/riscv32-toolchain-extra.c
index 59e2560b09c7..5df09029fc6f 100644
--- a/clang/test/Driver/riscv32-toolchain-extra.c
+++ b/clang/test/Driver/riscv32-toolchain-extra.c
@@ -11,25 +11,26 @@
 // The test below checks that the driver correctly finds the linker and
 // runtime if and only if they exist.
 //
-// RUN: rm -rf %T/testroot-riscv32-baremetal-nogcc
-// RUN: mkdir -p %T/testroot-riscv32-baremetal-nogcc/bin
-// RUN: ln -s %clang %T/testroot-riscv32-baremetal-nogcc/bin/clang
-// RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld 
%T/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld
-// RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf 
%T/testroot-riscv32-baremetal-nogcc/riscv32-unknown-elf
-// RUN: %T/testroot-riscv32-baremetal-nogcc/bin/clang %s -### 
-no-canonical-prefixes \
-// RUN:--gcc-toolchain=%T/testroot-riscv32-baremetal-nogcc/invalid \
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/riscv32-nogcc/bin
+// RUN: ln -s %clang %t/riscv32-nogcc/bin/clang
+// RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/bin/riscv32-unknown-elf-ld 
%t/riscv32-nogcc/bin/riscv32-unknown-elf-ld
+// RUN: ln -s %S/Inputs/basic_riscv32_nogcc_tree/riscv32-unknown-elf 
%t/riscv32-nogcc/riscv32-unknown-elf
+// RUN: %t/riscv32-nogcc/bin/clang %s -### -no-canonical-prefixes \
+// RUN:--gcc-toolchain=%t/riscv32-nogcc/invalid \
 // RUN:-target riscv32-unknown-elf --rtlib=platform -fuse-ld= 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC %s
 
-// RUN: %T/testroot-riscv32-baremetal-nogcc/bin/clang %s -### 
-no-canonical-prefixes \
+// RUN: %t/riscv32-nogcc/bin/clang %s -### -no-canonical-prefixes \
+// RUN:--sysroot=%t/riscv32-nogcc/bin/../riscv32-unknown-elf \
 // RUN:-target riscv32-unknown-elf --rtlib=platform -fuse-ld= 2>&1 \
 // RUN:| FileCheck -check-prefix=C-RV32-BAREMETAL-ILP32-NOGCC %s
 
-// C-RV32-BAREMETAL-ILP32-NOGCC: "-internal-isystem" 
"{{.*}}Output/testroot-riscv32-baremetal-nogcc/bin/../riscv32-unknown-elf/include"
-// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}Output/testroot-riscv32-baremetal-nogcc/bin/riscv32-unknown-elf-ld"
-// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}Output/testroot-riscv32-baremetal-nogcc/bin/../riscv32-unknown-elf/lib/crt0.o"
-// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}Output/testroot-riscv32-baremetal-nogcc/{{.*}}/lib/clang_rt.crtbegin-riscv32.o"
-// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}Output/testroot-riscv32-baremetal-nogcc/bin/../riscv32-unknown-elf/lib"
+// C-RV32-BAREMETAL-ILP32-NOGCC: "-internal-isystem" 
"{{.*}}/riscv32-nogcc/bin/../riscv32-unknown-elf/include"
+// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}/riscv32-nogcc/bin/riscv32-unknown-elf-ld"
+// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}/riscv32-nogcc/bin/../riscv32-unknown-elf/lib/crt0.o"
+// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}/riscv32-nogcc/{{.*}}/lib/clang_rt.crtbegin-riscv32.o"
+// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}/riscv32-nogcc/bin/../riscv32-unknown-elf/lib"
 // C-RV32-BAREMETAL-ILP32-NOGCC: "--start-group" "-lc" "-lgloss" "--end-group"
-// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}Output/testroot-riscv32-baremetal-nogcc/{{.*}}/lib/libclang_rt.builtins-riscv32.a"
-// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}Output/testroot-riscv32-baremetal-nogcc/{{.*}}/lib/clang_rt.crtend-riscv32.o"
+// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}/riscv32-nogcc/{{.*}}/lib/libclang_rt.builtins-riscv32.a"
+// C-RV32-BAREMETAL-ILP32-NOGCC: 
"{{.*}}/riscv32-nogcc/{{.*}}/lib/clang_rt.crtend-riscv32.o"

diff  --git a/clang/test/Driver/riscv64-toolchain-extra.c 
b/clang/test/Driver/riscv64-toolchain-extra.c
index 4412a90713d4..e6cae72ed2a2 100644
--- a/clang/test/Driver/risc