Skip to content

[flang/flang-rt] Add -isysroot flag only to tests really requiring #152914

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

Merged
merged 5 commits into from
Aug 13, 2025

Conversation

parabola94
Copy link
Contributor

-isysroot flag was added to all tests, but it makes Driver/darwin-version.f90 failed.

In fact, only a few tests regarding interoperability with C need -isysroot flag to search for headers and libraries. So, -isysroot flag is now eliminated from the substitution %flang, and a new substitution %isysroot has been introduced.

Moreover, Integration/iso-fortran-binding.cpp invokes clang++ via a shell script, which makes it hard to add -isysroot flag. So, it is refactored.

Fixes #150765

-isysroot flag was added to all tests, but it makes
Driver/darwin-version.f90 failed.

In fact, only a few tests need -isysroot flag. So, -isysroot flag
is now eliminated from the substitution `%flang`, and a new substitution
`%isysroot` has been introduced.

Moreover, Integration/iso-fortran-binding.cpp invokes clang++
via a shell script, which makes it hard to add -isysroot flag.
So, it is refactored.
@llvmbot llvmbot added the flang Flang issues not falling into any other category label Aug 10, 2025

# Include path for C headers that define Flang's Fortran ABI.
config.substitutions.append(
("%include", os.path.join(config.flang_source_dir, "include"))
Copy link
Member

Choose a reason for hiding this comment

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

What is this for? I comment it out and it still works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be necessary when building flang standalone.

/path/to/build/bin/clang --driver-mode=g++ -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk -I %include/flang /path/to/llvm-project/flang/test/Integration/iso-fortran-binding.cpp -o /path/to/build2/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp/a.out # RUN: at line 4
+ /path/to/build/bin/clang --driver-mode=g++ -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk -I %include/flang /path/to/llvm-project/flang/test/Integration/iso-fortran-binding.cpp -o /path/to/build2/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp/a.out
/path/to/llvm-project/flang/test/Integration/iso-fortran-binding.cpp:8:10: fatal error: 'ISO_Fortran_binding.h' file not found
    8 | #include "ISO_Fortran_binding.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

--

/path/to/build/bin/clang++ does not search /path/to/build2/lib/clang/22/include.

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

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

LGTM, thank you

@@ -6,10 +6,12 @@ import lit.util
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
config.host_triple = "@LLVM_HOST_TRIPLE@"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why has this been added? I don't see it being used anywhere in this PR - at least not directly.

Copy link
Member

Choose a reason for hiding this comment

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

It is used by llvm_config.use_clang(required=False). But it also has a fallback when not defined. Without e.g. the feature native is not defined. Not sure we strictly need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remove this line, I'll get the following error message. We could fix clang_setup by adding a check for hasattr(self.config, "host_triple"), but I'm not sure it is better.

llvm-lit: /path/to/llvm-project/llvm/utils/lit/lit/TestingConfig.py:157: fatal: unable to parse config file '/path/to/llvm-project/flang/test/lit.cfg.py', traceback: Traceback (most recent call last):
  File "/path/to/llvm-project/llvm/utils/lit/lit/TestingConfig.py", line 145, in load_from_path
    exec(compile(data, path, "exec"), cfg_globals, None)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/llvm-project/flang/test/lit.cfg.py", line 175, in <module>
    llvm_config.use_clang(required=False)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/path/to/llvm-project/llvm/utils/lit/lit/llvm/config.py", line 689, in use_clang
    self.clang_setup(additional_tool_dirs)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/llvm-project/llvm/utils/lit/lit/llvm/config.py", line 638, in clang_setup
    if self.config.host_triple and self.config.host_triple != "@LLVM_HOST_TRIPLE@":
       ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'TestingConfig' object has no attribute 'host_triple'

Copy link
Member

Choose a reason for hiding this comment

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

I've seen hasattr(self.config, "host_triple") at other places, seems that some change did not consider it may not be set.

Since we would want clang to know whether it is cross-compiling, I would keep config.host_triple = .. as-is.

Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

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

Except for @tarunprabhu's comments, LGTM, thanks.

Copy link

github-actions bot commented Aug 11, 2025

✅ With the latest revision this PR passed the Python code formatter.

@parabola94 parabola94 force-pushed the flang-isysroot-test branch from 3ceb84e to 0cef883 Compare August 11, 2025 23:31
Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@tarunprabhu tarunprabhu left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the changes

@parabola94 parabola94 enabled auto-merge (squash) August 13, 2025 21:23
@parabola94 parabola94 merged commit cc58ca5 into llvm:main Aug 13, 2025
9 checks passed
@parabola94 parabola94 deleted the flang-isysroot-test branch August 13, 2025 22:44
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 14, 2025

LLVM Buildbot has detected a new failure on builder ppc64-flang-aix running on ppc64-flang-aix-test while building flang-rt,flang at step 6 "test-build-unified-tree-check-flang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/201/builds/5894

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-flang) failure: test (failure)
******************** TEST 'Flang :: Integration/iso-fortran-binding.cpp' FAILED ********************
Exit Code: 2

Command Output (stderr):
--
rm -rf /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp && mkdir /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp # RUN: at line 3
+ rm -rf /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp
+ mkdir /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp
/home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/bin/clang --driver-mode=g++  -I/home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/./lib/../lib/clang/22/include /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/llvm-project/flang/test/Integration/iso-fortran-binding.cpp -o /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp/a.out # RUN: at line 4
+ /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/bin/clang --driver-mode=g++ -I/home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/./lib/../lib/clang/22/include /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/llvm-project/flang/test/Integration/iso-fortran-binding.cpp -o /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp/a.out
/home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp/a.out | /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/bin/FileCheck /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/llvm-project/flang/test/Integration/iso-fortran-binding.cpp # RUN: at line 5
+ /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp/a.out
+ /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/bin/FileCheck /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/llvm-project/flang/test/Integration/iso-fortran-binding.cpp
Could not load program /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/tools/flang/test/Integration/Output/iso-fortran-binding.cpp.tmp/a.out:
	Dependent module libc.a(shr_64.o) could not be loaded.
Could not load module libc.a(shr_64.o).
System error: No such file or directory
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/build/bin/FileCheck /home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/llvm-project/flang/test/Integration/iso-fortran-binding.cpp

--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] Some tests fail with SDKROOT on macOS
6 participants