Skip to content

Commit d3a8326

Browse files
RichBarton-Armbryanpkc
authored andcommitted
[driver] Add infrastructure for testing the flang-driver in lit
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]>
1 parent 92669bd commit d3a8326

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
! Test to see that the correct phases are run for the commandline input
2+
3+
! REQUIRES: classic_flang
4+
5+
! RUN: %flang -ccc-print-phases 2>&1 %s | FileCheck %s --check-prefix=LINK-NOPP
6+
! RUN: %flang -ccc-print-phases -c 2>&1 %s | FileCheck %s --check-prefix=CONLY-NOPP
7+
! RUN: %flang -ccc-print-phases -S 2>&1 %s | FileCheck %s --check-prefix=AONLY-NOPP
8+
! RUN: %flang -ccc-print-phases -c -emit-llvm 2>&1 %s | FileCheck %s --check-prefix=LLONLY-NOPP
9+
! RUN: %flang -ccc-print-phases -S -emit-llvm 2>&1 %s | FileCheck %s --check-prefix=LLONLY-NOPP
10+
! RUN: %flang -ccc-print-phases -fsyntax-only 2>&1 %s | FileCheck %s --check-prefix=SONLY-NOPP
11+
! RUN: %flang -ccc-print-phases -E 2>&1 %s | FileCheck %s --check-prefix=PPONLY-NOPP
12+
13+
! RUN: %flang -ccc-print-phases 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LINK
14+
! RUN: %flang -ccc-print-phases 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LINK
15+
! RUN: %flang -ccc-print-phases -c 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=CONLY
16+
! RUN: %flang -ccc-print-phases -S 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=AONLY
17+
! RUN: %flang -ccc-print-phases -c -emit-llvm 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LLONLY
18+
! RUN: %flang -ccc-print-phases -S -emit-llvm 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=LLONLY
19+
! RUN: %flang -ccc-print-phases -fsyntax-only 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=SONLY
20+
! RUN: %flang -ccc-print-phases -E 2>&1 -x f95-cpp-input %s | FileCheck %s --check-prefix=PPONLY
21+
22+
! LINK-NOPP: 0: input, {{.*}}, f95
23+
! LINK-NOPP: 1: compiler, {0}, ir
24+
! LINK-NOPP: 2: backend, {1}, assembler
25+
! LINK-NOPP: 3: assembler, {2}, object
26+
! LINK-NOPP: 4: linker, {3}, image
27+
28+
! CONLY-NOPP: 0: input, {{.*}}, f95
29+
! CONLY-NOPP: 1: compiler, {0}, ir
30+
! CONLY-NOPP: 2: backend, {1}, assembler
31+
! CONLY-NOPP: 3: assembler, {2}, object
32+
! CONLY-NOPP-NOT: 4: linker, {3}, image
33+
34+
! AONLY-NOPP: 0: input, {{.*}}, f95
35+
! AONLY-NOPP: 1: compiler, {0}, ir
36+
! AONLY-NOPP: 2: backend, {1}, assembler
37+
! AONLY-NOPP-NOT: 3: assembler, {2}, object
38+
! AONLY-NOPP-NOT: 4: linker, {3}, image
39+
40+
! LLONLY-NOPP: 0: input, {{.*}}, f95
41+
! LLONLY-NOPP: 1: compiler, {0}, ir
42+
! LLONLY-NOPP-NOT: 2: backend, {1}, assembler
43+
! LLONLY-NOPP-NOT: 3: assembler, {2}, object
44+
! LLONLY-NOPP-NOT: 4: linker, {3}, image
45+
46+
! SONLY-NOPP: 0: input, {{.*}}, f95
47+
! SONLY-NOPP-NOT: 1: compiler, {0}, ir
48+
! SONLY-NOPP-NOT: 2: backend, {1}, assembler
49+
! SONLY-NOPP-NOT: 3: assembler, {2}, object
50+
! SONLY-NOPP-NOT: 4: linker, {3}, image
51+
52+
! PPONLY-NOPP: 0: input, {{.*}}, f95
53+
! PPONLY-NOPP: 1: compiler, {0}, ir
54+
! PPONLY-NOPP-NOT: 2: backend, {1}, assembler
55+
! PPONLY-NOPP-NOT: 3: assembler, {2}, object
56+
! PPONLY-NOPP-NOT: 4: linker, {3}, image
57+
58+
! LINK: 0: input, {{.*}}, f95-cpp-input
59+
! LINK: 1: preprocessor, {0}, f95
60+
! LINK: 2: compiler, {1}, ir
61+
! LINK: 3: backend, {2}, assembler
62+
! LINK: 4: assembler, {3}, object
63+
! LINK: 5: linker, {4}, image
64+
65+
! CONLY: 0: input, {{.*}}, f95-cpp-input
66+
! CONLY: 1: preprocessor, {0}, f95
67+
! CONLY: 2: compiler, {1}, ir
68+
! CONLY: 3: backend, {2}, assembler
69+
! CONLY: 4: assembler, {3}, object
70+
! CONLY-NOT: 5: linker, {4}, image
71+
72+
! AONLY: 0: input, {{.*}}, f95-cpp-input
73+
! AONLY: 1: preprocessor, {0}, f95
74+
! AONLY: 2: compiler, {1}, ir
75+
! AONLY: 3: backend, {2}, assembler
76+
! AONLY-NOT: 4: assembler, {3}, object
77+
! AONLY-NOT: 5: linker, {4}, image
78+
79+
! LLONLY: 0: input, {{.*}}, f95-cpp-input
80+
! LLONLY: 1: preprocessor, {0}, f95
81+
! LLONLY: 2: compiler, {1}, ir
82+
! LLONLY-NOT: 3: backend, {2}, assembler
83+
! LLONLY-NOT: 4: assembler, {3}, object
84+
! LLONLY-NOT: 5: linker, {4}, image
85+
86+
! SONLY: 0: input, {{.*}}, f95-cpp-input
87+
! SONLY: 1: preprocessor, {0}, f95
88+
! SONLY-NOT: 2: compiler, {1}, ir
89+
! SONLY-NOT: 3: backend, {2}, assembler
90+
! SONLY-NOT: 4: assembler, {3}, object
91+
! SONLY-NOT: 5: linker, {4}, image
92+
93+
! PPONLY: 0: input, {{.*}}, f95-cpp-input
94+
! PPONLY: 1: preprocessor, {0}, f95
95+
! PPONLY: 2: compiler, {1}, ir
96+
! PPONLY-NOT: 3: backend, {2}, assembler
97+
! PPONLY-NOT: 4: assembler, {3}, object
98+
! PPONLY-NOT: 5: linker, {4}, image
99+
100+
program hello
101+
write(*, *) "Hello"
102+
end program hello

llvm/utils/lit/lit/TestingConfig.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def fromdefaults(litConfig):
2727
"TERM",
2828
"CLANG",
2929
"CLANG_TOOLCHAIN_PROGRAM_TIMEOUT",
30+
"FLANG",
3031
"LLDB",
3132
"LD_PRELOAD",
3233
"LLVM_SYMBOLIZER_PATH",

llvm/utils/lit/lit/llvm/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ def use_clang(
519519
just-built or optionally an installed clang, and add a set of standard
520520
substitutions useful to any test suite that makes use of clang.
521521
522+
Also sets up use of flang
523+
522524
"""
523525
# Clear some environment variables that might affect Clang.
524526
#
@@ -653,6 +655,14 @@ def use_clang(
653655
self.add_tool_substitutions(tool_substitutions)
654656
self.config.substitutions.append(("%resource_dir", builtin_include_dir))
655657

658+
self.config.flang = self.use_llvm_tool(
659+
'flang', search_env='FLANG', required=required)
660+
if self.config.flang:
661+
tool_substitutions = [
662+
ToolSubst('%flang', command=self.config.flang)
663+
]
664+
self.add_tool_substitutions(tool_substitutions)
665+
656666
# There will be no default target triple if one was not specifically
657667
# set, and the host's architecture is not an enabled target.
658668
if self.config.target_triple:

0 commit comments

Comments
 (0)