Skip to content

compilers-fortran: Fix preprocessing when fortran uses concat operator #14732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions mesonbuild/compilers/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ class IntelLLVMFortranCompiler(IntelFortranCompiler):

id = 'intel-llvm'

def get_preprocess_only_args(self) -> T.List[str]:
return ['-preprocess-only']

def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
return []

class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):

Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/compilers/mixins/gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ def get_preprocess_to_file_args(self) -> T.List[str]:
# We want to allow preprocessing files with any extension, such as
# foo.c.in. In that case we need to tell GCC/CLANG to treat them as
# assembly file.
if self.language == 'fortran':
return self.get_preprocess_only_args()
Comment on lines +537 to +538
Copy link
Member

Choose a reason for hiding this comment

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

If we can't handle this via the language map, I think I'd prefer to just add an overriding implementation to the GnuFortran class that simply does return self.get_preprocess_only_args() than special case fortran here, unless that makes for lots of duplication in leaf classes.

Copy link
Author

Choose a reason for hiding this comment

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

Looks like GNULikeCompiler is a mixin for these classes. Happy to override in these classes if you prefer:

  • ClassicFlangFortranCompiler
  • LlvmFlangFortranCompiler
  • ElbrusFortranCompiler
  • GnuFortranCompiler
  • IntelFortranCompiler

I can test that this is an issue on the final 2 and verify it's fixed. For the other 3, I can leave them as they are or update without testing (unless that's done by CI?).

Copy link
Author

Choose a reason for hiding this comment

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

I suppose this could be in the language map if we had something like:

gnu_lang_map = {
    'c': 'c',
    'cpp': 'c++',
    'objc': 'objective-c',
    'objcpp': 'objective-c++',
    'fortran': ''
}
def gnulike_default_include_dirs(compiler: T.Tuple[str, ...], lang: str) -> 'ImmutableListProtocol[str]':
    lang = gnu_lang_map.get(lang, '')
    if not lang:
        return []
    ...

and

        lang = gnu_lang_map.get(self.language, 'assembler-with-cpp')
        if not lang:
            return self.get_preprocess_only_args()
        return self.get_preprocess_only_args() + [f'-x{lang}']

this might be a bit more generalised though I don't know if it's better than just doing the override in the FortranCompiler subclasses... Let me know which to update to and I can make the change.

lang = gnu_lang_map.get(self.language, 'assembler-with-cpp')
return self.get_preprocess_only_args() + [f'-x{lang}']

Expand Down
12 changes: 11 additions & 1 deletion test cases/fortran/23 preprocess/main.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#define MYDEF program
MYDEF foo
write (*,*) 'Hello, world!'
character(20) :: str
#ifdef CORRECT
str = 'Hello, ' // 'world!'
#else
str = 'Preprocessing error!'
#endif
if (str /= 'Hello, world!') then
print *, 'Preprocessing failed.'
error stop 1
end if
stop 0
end MYDEF foo
11 changes: 8 additions & 3 deletions test cases/fortran/23 preprocess/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
project('preprocess', 'fortran')
project('preprocess', 'fortran', meson_version: '>1.3.2')

fc = meson.get_compiler('fortran')

pp_files = fc.preprocess('main.f90', output: '@PLAINNAME@')
pp_files = fc.preprocess(
'main.f90',
compile_args: ['-DCORRECT=true'],
output: '@PLAINNAME@')

library('foo', pp_files)
t = executable('foo', pp_files)

test('check_result', t)
Loading