1ba36147a8
Wire flang into llvmPackages as a first-class Fortran compiler. flang
is built standalone on top of the LLVM/clang package set rather than
bundled into the llvm derivation, with passthru metadata
(`langFortran`, `isFlang`, `isClang`, `hardeningUnsupportedFlags`) so
cc-wrapper and downstream tooling can detect and adapt to it.
Driver compatibility patches backported from upstream are applied
selectively per LLVM version:
* `use-xflang-in-diagnostics` is applied to LLVM 20 and newer; it
teaches the driver to suggest `-Xflang` instead of `-Xclang` in
error messages for options only available to `flang -fc1`.
* `warn-on-fbuiltin-and-fno-builtin` and
`accept-and-ignore-some-gfortran-optimization-flags` are applied
to LLVM 20 and 21 only. LLVM 22 has equivalent behaviour merged
upstream (`warn_drv_invalid_argument_for_flang` and
`clang_ignored_gcc_optimization_f_Group` handling in
clang/lib/Driver/ToolChains/Flang.cpp), so the patches are skipped
there.
Patches live under pkgs/development/compilers/llvm/21/flang/ and are
shared across versions via patches.nix. They are applied to a private
libclang variant rather than the flang source tree because standalone
flang resolves driver/option definitions through the installed libclang
package.
Two focused passthru tests are added:
* `compile-smoke` exercises basic compilation and `@response-file`
handling.
* `driver-flags` covers wrapper flag isolation
(`NIX_CFLAGS_COMPILE` must not leak into flang;
`NIX_FFLAGS_COMPILE` must reach it), the backported driver
diagnostics, and regression coverage for previously hard-erroring
flags.
Build on the earlier standalone flang work by @picostove.
Co-authored-by: stove <stove@rivosinc.com>
Co-authored-by: acture <acture@gmail.com>
Co-authored-by: Alyssa Ross <hi@alyssa.is>
41 lines
1.7 KiB
Diff
41 lines
1.7 KiB
Diff
From 9ab9d33171ee35c948967a2a2d714b8059887607 Mon Sep 17 00:00:00 2001
|
|
From: Tarun Prabhu <tarun@lanl.gov>
|
|
Date: Wed, 29 Oct 2025 09:13:17 -0600
|
|
Subject: [PATCH] [flang][driver] Use -Xflang in diagnostics
|
|
|
|
When an option that is only available in `flang -fc1` is provided to
|
|
`flang`, emit a diagnostic with a suggestion containing "did you mean
|
|
-Xflang '-foo'".
|
|
|
|
Partially addresses #163550.
|
|
---
|
|
clang/lib/Driver/Driver.cpp | 15 ++++++++++++---
|
|
1 file changed, 12 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
|
|
index 40ea513e85427..71c52807091ba 100644
|
|
--- a/lib/Driver/Driver.cpp
|
|
+++ b/lib/Driver/Driver.cpp
|
|
@@ -365,9 +365,18 @@
|
|
auto ArgString = A->getAsString(Args);
|
|
std::string Nearest;
|
|
if (getOpts().findNearest(ArgString, Nearest, VisibilityMask) > 1) {
|
|
- if (!IsCLMode() &&
|
|
- getOpts().findExact(ArgString, Nearest,
|
|
- llvm::opt::Visibility(options::CC1Option))) {
|
|
+ if (IsFlangMode()) {
|
|
+ if (getOpts().findExact(ArgString, Nearest,
|
|
+ llvm::opt::Visibility(options::FC1Option))) {
|
|
+ DiagID = diag::err_drv_unknown_argument_with_suggestion;
|
|
+ Diags.Report(DiagID) << ArgString << "-Xflang " + Nearest;
|
|
+ } else {
|
|
+ DiagID = diag::err_drv_unknown_argument;
|
|
+ Diags.Report(DiagID) << ArgString;
|
|
+ }
|
|
+ } else if (!IsCLMode() && getOpts().findExact(ArgString, Nearest,
|
|
+ llvm::opt::Visibility(
|
|
+ options::CC1Option))) {
|
|
DiagID = diag::err_drv_unknown_argument_with_suggestion;
|
|
Diags.Report(DiagID) << ArgString << "-Xclang " + Nearest;
|
|
} else {
|