[flang] Align -x language modes with gfortran (#130268)

This PR addresses some of the issues described in
https://github.com/llvm/llvm-project/issues/127617. Key changes:

- Stop assuming fixed-form for `-x f95` unless the input is a `.i` file.
This change ensures compatibility with `-save-temps` workflows while
preventing unintended fixed-form assumptions.
- Ensure `-x f95-cpp-input` enables `-cpp` by default, aligning Flang's
behavior with `gfortran`.
This commit is contained in:
Iñaki Amatria Barral
2025-03-12 16:45:33 +01:00
committed by GitHub
parent 1db978cd78
commit bdbe8fa1f3
5 changed files with 61 additions and 3 deletions

View File

@@ -863,6 +863,12 @@ static void parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
(currentArg->getOption().matches(clang::driver::options::OPT_cpp))
? PPMacrosFlag::Include
: PPMacrosFlag::Exclude;
// Enable -cpp based on -x unless explicitly disabled with -nocpp
if (opts.macrosFlag != PPMacrosFlag::Exclude)
if (const auto *dashX = args.getLastArg(clang::driver::options::OPT_x))
opts.macrosFlag = llvm::StringSwitch<PPMacrosFlag>(dashX->getValue())
.Case("f95-cpp-input", PPMacrosFlag::Include)
.Default(opts.macrosFlag);
opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
opts.preprocessIncludeLines =