From bdbe8fa1f3dcde77f7e0741ea7fa757ce092a420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= <140811900+inaki-amatria@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:45:33 +0100 Subject: [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`. --- flang/lib/Frontend/CompilerInvocation.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 8b07a50..1537122 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -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(dashX->getValue()) + .Case("f95-cpp-input", PPMacrosFlag::Include) + .Default(opts.macrosFlag); opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat); opts.preprocessIncludeLines = -- cgit v1.1