Skip to content

Commit

Permalink
[driver] Add infrastructure for testing the flang-driver in lit
Browse files Browse the repository at this point in the history
Add %flang as a tool substitution available in lit tests. This apes the way
%clang is defined and adds a $FLANG override in a similar vein.

To avoid this being dead code, add a single test to check the flang driver is
reporting the correct phases when running under various phase control options.

Signed-off-by: Richard Barton <[email protected]>
  • Loading branch information
RichBarton-Arm authored and bryanpkc committed Mar 20, 2024
1 parent dbfc054 commit eddbab0
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
102 changes: 102 additions & 0 deletions clang/test/Driver/fortran-phases.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
! Test to see that the correct phases are run for the commandline input

! REQUIRES: classic_flang

! RUN: %flang -ccc-print-phases 2>&1 %s | FileCheck %s --check-prefix=LINK-NOPP
! RUN: %flang -ccc-print-phases -c 2>&1 %s | FileCheck %s --check-prefix=CONLY-NOPP
! RUN: %flang -ccc-print-phases -S 2>&1 %s | FileCheck %s --check-prefix=AONLY-NOPP
! RUN: %flang -ccc-print-phases -c -emit-llvm 2>&1 %s | FileCheck %s --check-prefix=LLONLY-NOPP
! RUN: %flang -ccc-print-phases -S -emit-llvm 2>&1 %s | FileCheck %s --check-prefix=LLONLY-NOPP
! RUN: %flang -ccc-print-phases -fsyntax-only 2>&1 %s | FileCheck %s --check-prefix=SONLY-NOPP
! RUN: %flang -ccc-print-phases -E 2>&1 %s | FileCheck %s --check-prefix=PPONLY-NOPP

! RUN: %flang -ccc-print-phases 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LINK
! RUN: %flang -ccc-print-phases 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LINK
! RUN: %flang -ccc-print-phases -c 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=CONLY
! RUN: %flang -ccc-print-phases -S 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=AONLY
! RUN: %flang -ccc-print-phases -c -emit-llvm 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LLONLY
! RUN: %flang -ccc-print-phases -S -emit-llvm 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LLONLY
! RUN: %flang -ccc-print-phases -fsyntax-only 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=SONLY
! RUN: %flang -ccc-print-phases -E 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=PPONLY

! LINK-NOPP: 0: input, {{.*}}, f95
! LINK-NOPP: 1: compiler, {0}, ir
! LINK-NOPP: 2: backend, {1}, assembler
! LINK-NOPP: 3: assembler, {2}, object
! LINK-NOPP: 4: linker, {3}, image

! CONLY-NOPP: 0: input, {{.*}}, f95
! CONLY-NOPP: 1: compiler, {0}, ir
! CONLY-NOPP: 2: backend, {1}, assembler
! CONLY-NOPP: 3: assembler, {2}, object
! CONLY-NOPP-NOT: 4: linker, {3}, image

! AONLY-NOPP: 0: input, {{.*}}, f95
! AONLY-NOPP: 1: compiler, {0}, ir
! AONLY-NOPP: 2: backend, {1}, assembler
! AONLY-NOPP-NOT: 3: assembler, {2}, object
! AONLY-NOPP-NOT: 4: linker, {3}, image

! LLONLY-NOPP: 0: input, {{.*}}, f95
! LLONLY-NOPP: 1: compiler, {0}, ir
! LLONLY-NOPP-NOT: 2: backend, {1}, assembler
! LLONLY-NOPP-NOT: 3: assembler, {2}, object
! LLONLY-NOPP-NOT: 4: linker, {3}, image

! SONLY-NOPP: 0: input, {{.*}}, f95
! SONLY-NOPP-NOT: 1: compiler, {0}, ir
! SONLY-NOPP-NOT: 2: backend, {1}, assembler
! SONLY-NOPP-NOT: 3: assembler, {2}, object
! SONLY-NOPP-NOT: 4: linker, {3}, image

! PPONLY-NOPP: 0: input, {{.*}}, f95
! PPONLY-NOPP: 1: compiler, {0}, ir
! PPONLY-NOPP-NOT: 2: backend, {1}, assembler
! PPONLY-NOPP-NOT: 3: assembler, {2}, object
! PPONLY-NOPP-NOT: 4: linker, {3}, image

! LINK: 0: input, {{.*}}, f95-cpp-input
! LINK: 1: preprocessor, {0}, f95
! LINK: 2: compiler, {1}, ir
! LINK: 3: backend, {2}, assembler
! LINK: 4: assembler, {3}, object
! LINK: 5: linker, {4}, image

! CONLY: 0: input, {{.*}}, f95-cpp-input
! CONLY: 1: preprocessor, {0}, f95
! CONLY: 2: compiler, {1}, ir
! CONLY: 3: backend, {2}, assembler
! CONLY: 4: assembler, {3}, object
! CONLY-NOT: 5: linker, {4}, image

! AONLY: 0: input, {{.*}}, f95-cpp-input
! AONLY: 1: preprocessor, {0}, f95
! AONLY: 2: compiler, {1}, ir
! AONLY: 3: backend, {2}, assembler
! AONLY-NOT: 4: assembler, {3}, object
! AONLY-NOT: 5: linker, {4}, image

! LLONLY: 0: input, {{.*}}, f95-cpp-input
! LLONLY: 1: preprocessor, {0}, f95
! LLONLY: 2: compiler, {1}, ir
! LLONLY-NOT: 3: backend, {2}, assembler
! LLONLY-NOT: 4: assembler, {3}, object
! LLONLY-NOT: 5: linker, {4}, image

! SONLY: 0: input, {{.*}}, f95-cpp-input
! SONLY: 1: preprocessor, {0}, f95
! SONLY-NOT: 2: compiler, {1}, ir
! SONLY-NOT: 3: backend, {2}, assembler
! SONLY-NOT: 4: assembler, {3}, object
! SONLY-NOT: 5: linker, {4}, image

! PPONLY: 0: input, {{.*}}, f95-cpp-input
! PPONLY: 1: preprocessor, {0}, f95
! PPONLY: 2: compiler, {1}, ir
! PPONLY-NOT: 3: backend, {2}, assembler
! PPONLY-NOT: 4: assembler, {3}, object
! PPONLY-NOT: 5: linker, {4}, image

program hello
write(*, *) "Hello"
end program hello
1 change: 1 addition & 0 deletions llvm/utils/lit/lit/TestingConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def fromdefaults(litConfig):
"SYSTEMROOT",
"TERM",
"CLANG",
"FLANG",
"LLDB",
"LD_PRELOAD",
"LLVM_SYMBOLIZER_PATH",
Expand Down
10 changes: 10 additions & 0 deletions llvm/utils/lit/lit/llvm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ def use_clang(
just-built or optionally an installed clang, and add a set of standard
substitutions useful to any test suite that makes use of clang.
Also sets up use of flang
"""
# Clear some environment variables that might affect Clang.
#
Expand Down Expand Up @@ -646,6 +648,14 @@ def use_clang(
self.add_tool_substitutions(tool_substitutions)
self.config.substitutions.append(("%resource_dir", builtin_include_dir))

self.config.flang = self.use_llvm_tool(
'flang', search_env='FLANG', required=required)
if self.config.flang:
tool_substitutions = [
ToolSubst('%flang', command=self.config.flang)
]
self.add_tool_substitutions(tool_substitutions)

# There will be no default target triple if one was not specifically
# set, and the host's architecture is not an enabled target.
if self.config.target_triple:
Expand Down

0 comments on commit eddbab0

Please sign in to comment.