Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl<const char *> &Args,
/// See applyOneOverrideOption.
void applyOverrideOptions(SmallVectorImpl<const char *> &Args,
const char *OverrideOpts,
llvm::StringSet<> &SavedStrings,
llvm::StringSet<> &SavedStrings, StringRef EnvVar,
raw_ostream *OS = nullptr);

} // end namespace driver
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
void driver::applyOverrideOptions(SmallVectorImpl<const char *> &Args,
const char *OverrideStr,
llvm::StringSet<> &SavedStrings,
raw_ostream *OS) {
StringRef EnvVar, raw_ostream *OS) {
if (!OS)
OS = &llvm::nulls();

Expand All @@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl<const char *> &Args,
OS = &llvm::nulls();
}

*OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
*OS << "### " << EnvVar << ": " << OverrideStr << "\n";

// This does not need to be efficient.

Expand Down
2 changes: 1 addition & 1 deletion clang/tools/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions flang/docs/FlangDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that clang/docs doesn't have the documentation. Perhaps we should document clang/docs/UsersManual.rst as well and reference it from FlangDriver.md?

("Each edit should be one of the following forms:" list should probably reference the clang doc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this?

Suggested change
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:
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:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


- `#`: Silence information about the changes to the command line arguments.

- `^FOO`: Add `FOO` as a new argument at the beginning of the command line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clang a.cc, this actually adds FOO after clang. The comment in clang/lib/Driver/Driver.cpp and this description probably should be made more accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


- `+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.
12 changes: 12 additions & 0 deletions flang/test/Driver/fcc_override.f90
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does +, x,X have special meanings? Is that documented anywhere?

I think we should document FCC_OVERRIDE_OPTIONS. One possible location is https://github.com/llvm/llvm-project/blob/main/flang/docs/FlangDriver.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--target=x86_64-unknown-linux-gnu instead of the long deprecated -target

Copy link
Contributor

@tarunprabhu tarunprabhu May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be --target?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Thanks for catching this. Fixed now.

! 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"
7 changes: 7 additions & 0 deletions flang/tools/flang-driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
}
}

llvm::StringSet<> SavedStrings;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
llvm::StringSet<> SavedStrings;
llvm::StringSet<> savedStrings;

// Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
// scenes.
if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
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
Expand Down
Loading