Skip to content

Commit 28412d1

Browse files
committed
[lit] Implement DEFINE and REDEFINE directives
These directives define per-test lit substitutions. The concept was discussed at <https://discourse.llvm.org/t/iterating-lit-run-lines/62596/10>. For example, the following directives can be inserted into a test file to define `%{cflags}` and `%{fcflags}` substitutions with empty initial values, which serve as the parameters of another newly defined `%{check}` substitution: ``` // DEFINE: %{cflags} = // DEFINE: %{fcflags} = // DEFINE: %{check} = %clang_cc1 %{cflags} -emit-llvm -o - %s | \ // DEFINE: FileCheck %{fcflags} %s ``` The following directives then redefine the parameters before each use of `%{check}`: ``` // REDEFINE: %{cflags} = -foo // REDEFINE: %{fcflags} = -check-prefix=FOO // RUN: %{check} // REDEFINE: %{cflags} = -bar // REDEFINE: %{fcflags} = -check-prefix=BAR // RUN: %{check} ``` Of course, `%{check}` would typically be more elaborate, increasing the benefit of the reuse. One issue is that the strings `DEFINE:` and `REDEFINE:` already appear in 5 tests. This patch adjusts those tests not to use those strings. Our prediction is that, in the vast majority of cases, if a test author mistakenly uses one of those strings for another purpose, the text appearing after the string will not happen to have the syntax required for these directives. Thus, the test author will discover the mistake immediately when lit reports the syntax error. This patch also expands the documentation on existing lit substitution behavior. Reviewed By: jhenderson, MaskRay, awarzynski Differential Revision: https://reviews.llvm.org/D132513
1 parent bc97751 commit 28412d1

File tree

67 files changed

+1537
-85
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1537
-85
lines changed

clang/test/CodeGen/attr-noundef.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ struct Trivial {
1515
};
1616
Trivial ret_trivial() { return {}; }
1717
void pass_trivial(Trivial e) {}
18-
// CHECK-INTEL: [[DEFINE:define( dso_local)?]] i32 @{{.*}}ret_trivial
19-
// CHECK-AARCH: [[DEFINE:define( dso_local)?]] i32 @{{.*}}ret_trivial
20-
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
21-
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
18+
// CHECK-INTEL: [[DEF:define( dso_local)?]] i32 @{{.*}}ret_trivial
19+
// CHECK-AARCH: [[DEF:define( dso_local)?]] i32 @{{.*}}ret_trivial
20+
// CHECK-INTEL: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i32 %
21+
// CHECK-AARCH: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i64 %
2222

2323
struct NoCopy {
2424
int a;
2525
NoCopy(NoCopy &) = delete;
2626
};
2727
NoCopy ret_nocopy() { return {}; }
2828
void pass_nocopy(NoCopy e) {}
29-
// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noalias sret({{[^)]+}}) align 4 %
30-
// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noundef %
29+
// CHECK: [[DEF]] void @{{.*}}ret_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noalias sret({{[^)]+}}) align 4 %
30+
// CHECK: [[DEF]] void @{{.*}}pass_nocopy{{.*}}(%"struct.check_structs::NoCopy"* noundef %
3131

3232
struct Huge {
3333
int a[1024];
3434
};
3535
Huge ret_huge() { return {}; }
3636
void pass_huge(Huge h) {}
37-
// CHECK: [[DEFINE]] void @{{.*}}ret_huge{{.*}}(%"struct.check_structs::Huge"* noalias sret({{[^)]+}}) align 4 %
38-
// CHECK: [[DEFINE]] void @{{.*}}pass_huge{{.*}}(%"struct.check_structs::Huge"* noundef
37+
// CHECK: [[DEF]] void @{{.*}}ret_huge{{.*}}(%"struct.check_structs::Huge"* noalias sret({{[^)]+}}) align 4 %
38+
// CHECK: [[DEF]] void @{{.*}}pass_huge{{.*}}(%"struct.check_structs::Huge"* noundef
3939
} // namespace check_structs
4040

4141
//************ Passing unions by value
@@ -47,19 +47,19 @@ union Trivial {
4747
};
4848
Trivial ret_trivial() { return {}; }
4949
void pass_trivial(Trivial e) {}
50-
// CHECK-INTEL: [[DEFINE]] i32 @{{.*}}ret_trivial
51-
// CHECK-AARCH: [[DEFINE]] i32 @{{.*}}ret_trivial
52-
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i32 %
53-
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_trivial{{.*}}(i64 %
50+
// CHECK-INTEL: [[DEF]] i32 @{{.*}}ret_trivial
51+
// CHECK-AARCH: [[DEF]] i32 @{{.*}}ret_trivial
52+
// CHECK-INTEL: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i32 %
53+
// CHECK-AARCH: [[DEF]] void @{{.*}}pass_trivial{{.*}}(i64 %
5454

5555
union NoCopy {
5656
int a;
5757
NoCopy(NoCopy &) = delete;
5858
};
5959
NoCopy ret_nocopy() { return {}; }
6060
void pass_nocopy(NoCopy e) {}
61-
// CHECK: [[DEFINE]] void @{{.*}}ret_nocopy{{.*}}(%"union.check_unions::NoCopy"* noalias sret({{[^)]+}}) align 4 %
62-
// CHECK: [[DEFINE]] void @{{.*}}pass_nocopy{{.*}}(%"union.check_unions::NoCopy"* noundef %
61+
// CHECK: [[DEF]] void @{{.*}}ret_nocopy{{.*}}(%"union.check_unions::NoCopy"* noalias sret({{[^)]+}}) align 4 %
62+
// CHECK: [[DEF]] void @{{.*}}pass_nocopy{{.*}}(%"union.check_unions::NoCopy"* noundef %
6363
} // namespace check_unions
6464

6565
//************ Passing `this` pointers
@@ -100,9 +100,9 @@ i32x3 ret_vec() {
100100
void pass_vec(i32x3 v) {
101101
}
102102

103-
// CHECK: [[DEFINE]] noundef <3 x i32> @{{.*}}ret_vec{{.*}}()
104-
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_vec{{.*}}(<3 x i32> noundef %
105-
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_vec{{.*}}(<4 x i32> %
103+
// CHECK: [[DEF]] noundef <3 x i32> @{{.*}}ret_vec{{.*}}()
104+
// CHECK-INTEL: [[DEF]] void @{{.*}}pass_vec{{.*}}(<3 x i32> noundef %
105+
// CHECK-AARCH: [[DEF]] void @{{.*}}pass_vec{{.*}}(<4 x i32> %
106106
} // namespace check_vecs
107107

108108
//************ Passing exotic types
@@ -145,23 +145,23 @@ void pass_large_BitInt(_BitInt(127) e) {
145145
}
146146

147147
// Pointers to arrays/functions are always noundef
148-
// CHECK: [[DEFINE]] noundef [32 x i32]* @{{.*}}ret_arrptr{{.*}}()
149-
// CHECK: [[DEFINE]] noundef i32 (i32)* @{{.*}}ret_fnptr{{.*}}()
148+
// CHECK: [[DEF]] noundef [32 x i32]* @{{.*}}ret_arrptr{{.*}}()
149+
// CHECK: [[DEF]] noundef i32 (i32)* @{{.*}}ret_fnptr{{.*}}()
150150

151151
// Pointers to members are never noundef
152-
// CHECK: [[DEFINE]] i64 @{{.*}}ret_mdptr{{.*}}()
153-
// CHECK-INTEL: [[DEFINE]] { i64, i64 } @{{.*}}ret_mfptr{{.*}}()
154-
// CHECK-AARCH: [[DEFINE]] [2 x i64] @{{.*}}ret_mfptr{{.*}}()
152+
// CHECK: [[DEF]] i64 @{{.*}}ret_mdptr{{.*}}()
153+
// CHECK-INTEL: [[DEF]] { i64, i64 } @{{.*}}ret_mfptr{{.*}}()
154+
// CHECK-AARCH: [[DEF]] [2 x i64] @{{.*}}ret_mfptr{{.*}}()
155155

156156
// nullptr_t is never noundef
157-
// CHECK: [[DEFINE]] i8* @{{.*}}ret_npt{{.*}}()
158-
// CHECK: [[DEFINE]] void @{{.*}}pass_npt{{.*}}(i8* %
157+
// CHECK: [[DEF]] i8* @{{.*}}ret_npt{{.*}}()
158+
// CHECK: [[DEF]] void @{{.*}}pass_npt{{.*}}(i8* %
159159

160160
// TODO: for now, ExtInt is only noundef if it is sign/zero-extended
161-
// CHECK-INTEL: [[DEFINE]] noundef signext i3 @{{.*}}ret_BitInt{{.*}}()
162-
// CHECK-AARCH: [[DEFINE]] i3 @{{.*}}ret_BitInt{{.*}}()
163-
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_BitInt{{.*}}(i3 noundef signext %
164-
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_BitInt{{.*}}(i3 %
165-
// CHECK-INTEL: [[DEFINE]] void @{{.*}}pass_large_BitInt{{.*}}(i64 %{{.*}}, i64 %
166-
// CHECK-AARCH: [[DEFINE]] void @{{.*}}pass_large_BitInt{{.*}}(i127 %
161+
// CHECK-INTEL: [[DEF]] noundef signext i3 @{{.*}}ret_BitInt{{.*}}()
162+
// CHECK-AARCH: [[DEF]] i3 @{{.*}}ret_BitInt{{.*}}()
163+
// CHECK-INTEL: [[DEF]] void @{{.*}}pass_BitInt{{.*}}(i3 noundef signext %
164+
// CHECK-AARCH: [[DEF]] void @{{.*}}pass_BitInt{{.*}}(i3 %
165+
// CHECK-INTEL: [[DEF]] void @{{.*}}pass_large_BitInt{{.*}}(i64 %{{.*}}, i64 %
166+
// CHECK-AARCH: [[DEF]] void @{{.*}}pass_large_BitInt{{.*}}(i127 %
167167
} // namespace check_exotic

clang/test/CodeGen/indirect-noundef.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ int (*indirect_callee_int_ptr)(int);
1313
// CHECK: @indirect_callee_union_ptr = [[GLOBAL]] i32 (i32)*
1414
union u1 (*indirect_callee_union_ptr)(union u1);
1515

16-
// CHECK: [[DEFINE:define( dso_local)?]] noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef %
16+
// CHECK: [[DEF:define( dso_local)?]] noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef %
1717
int indirect_callee_int(int a) { return a; }
18-
// CHECK: [[DEFINE]] i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
18+
// CHECK: [[DEF]] i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
1919
union u1 indirect_callee_union(union u1 a) {
2020
return a;
2121
}

clang/test/Preprocessor/init.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,13 +1396,13 @@
13961396
// SPARC64-OBSD:#define __UINTMAX_C_SUFFIX__ ULL
13971397
// SPARC64-OBSD:#define __UINTMAX_TYPE__ long long unsigned int
13981398
//
1399-
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-pc-kfreebsd-gnu < /dev/null | FileCheck -match-full-lines -check-prefix KFREEBSD-DEFINE %s
1400-
// KFREEBSD-DEFINE:#define __FreeBSD_kernel__ 1
1401-
// KFREEBSD-DEFINE:#define __GLIBC__ 1
1399+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-pc-kfreebsd-gnu < /dev/null | FileCheck -match-full-lines -check-prefix KFREEBSD-DEF %s
1400+
// KFREEBSD-DEF:#define __FreeBSD_kernel__ 1
1401+
// KFREEBSD-DEF:#define __GLIBC__ 1
14021402
//
1403-
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i686-pc-kfreebsd-gnu < /dev/null | FileCheck -match-full-lines -check-prefix KFREEBSDI686-DEFINE %s
1404-
// KFREEBSDI686-DEFINE:#define __FreeBSD_kernel__ 1
1405-
// KFREEBSDI686-DEFINE:#define __GLIBC__ 1
1403+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i686-pc-kfreebsd-gnu < /dev/null | FileCheck -match-full-lines -check-prefix KFREEBSDI686-DEF %s
1404+
// KFREEBSDI686-DEF:#define __FreeBSD_kernel__ 1
1405+
// KFREEBSDI686-DEF:#define __GLIBC__ 1
14061406
//
14071407
// RUN: %clang_cc1 -x c++ -triple i686-pc-linux-gnu -fobjc-runtime=gcc -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GNUSOURCE %s
14081408
// RUN: %clang_cc1 -x c++ -triple sparc-rtems-elf -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GNUSOURCE %s

llvm/docs/CommandGuide/lit.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,14 +562,6 @@ Other substitutions are provided that are variations on this base set and
562562
further substitution patterns can be defined by each test module. See the
563563
modules :ref:`local-configuration-files`.
564564

565-
By default, substitutions are expanded exactly once, so that if e.g. a
566-
substitution ``%build`` is defined in top of another substitution ``%cxx``,
567-
``%build`` will expand to ``%cxx`` textually, not to what ``%cxx`` expands to.
568-
However, if the ``recursiveExpansionLimit`` property of the ``TestingConfig``
569-
is set to a non-negative integer, substitutions will be expanded recursively
570-
until that limit is reached. It is an error if the limit is reached and
571-
expanding substitutions again would yield a different result.
572-
573565
More detailed information on substitutions can be found in the
574566
:doc:`../TestingGuide`.
575567

llvm/docs/TestingGuide.rst

Lines changed: 201 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,15 @@ RUN lines:
619619
``%else %{<else branch>%}`` is optional and treated like ``%else %{%}``
620620
if not present.
621621

622+
``%(line)``, ``%(line+<number>)``, ``%(line-<number>)``
623+
624+
The number of the line where this substitution is used, with an
625+
optional integer offset. These expand only if they appear
626+
immediately in ``RUN:``, ``DEFINE:``, and ``REDEFINE:`` directives.
627+
Occurrences in substitutions defined elsewhere are never expanded.
628+
For example, this can be used in tests with multiple RUN lines,
629+
which reference the test file's line numbers.
630+
622631
**LLVM-specific substitutions:**
623632

624633
``%shlibext``
@@ -633,12 +642,6 @@ RUN lines:
633642

634643
Example: ``.exe`` (Windows), empty on Linux.
635644

636-
``%(line)``, ``%(line+<number>)``, ``%(line-<number>)``
637-
The number of the line where this substitution is used, with an optional
638-
integer offset. This can be used in tests with multiple RUN lines, which
639-
reference test file's line numbers.
640-
641-
642645
**Clang-specific substitutions:**
643646

644647
``%clang``
@@ -670,8 +673,199 @@ RUN lines:
670673
output affects test results. It's usually easy to tell: just look for
671674
redirection or piping of the ``FileCheck`` call's stdout or stderr.
672675

673-
To add more substitutions, look at ``test/lit.cfg`` or ``lit.local.cfg``.
676+
.. _Test-specific substitutions:
677+
678+
**Test-specific substitutions:**
679+
680+
Additional substitutions can be defined as follows:
681+
682+
- Lit configuration files (e.g., ``lit.cfg`` or ``lit.local.cfg``) can define
683+
substitutions for all tests in a test directory. They do so by extending the
684+
substitution list, ``config.substitutions``. Each item in the list is a tuple
685+
consisting of a pattern and its replacement, which lit applies using python's
686+
``re.sub`` function.
687+
- To define substitutions within a single test file, lit supports the
688+
``DEFINE:`` and ``REDEFINE:`` directives, described in detail below. So that
689+
they have no effect on other test files, these directives modify a copy of the
690+
substitution list that is produced by lit configuration files.
691+
692+
For example, the following directives can be inserted into a test file to define
693+
``%{cflags}`` and ``%{fcflags}`` substitutions with empty initial values, which
694+
serve as the parameters of another newly defined ``%{check}`` substitution:
695+
696+
.. code-block:: llvm
697+
698+
; DEFINE: %{cflags} =
699+
; DEFINE: %{fcflags} =
700+
701+
; DEFINE: %{check} = \
702+
; DEFINE: %clang_cc1 -verify -fopenmp -fopenmp-version=51 %{cflags} \
703+
; DEFINE: -emit-llvm -o - %s | \
704+
; DEFINE: FileCheck %{fcflags} %s
705+
706+
Alternatively, the above substitutions can be defined in a lit configuration
707+
file to be shared with other test files. Either way, the test file can then
708+
specify directives like the following to redefine the parameter substitutions as
709+
desired before each use of ``%{check}`` in a ``RUN:`` line:
710+
711+
.. code-block:: llvm
712+
713+
; REDEFINE: %{cflags} = -triple x86_64-apple-darwin10.6.0 -fopenmp-simd
714+
; REDEFINE: %{fcflags} = -check-prefix=SIMD
715+
; RUN: %{check}
716+
717+
; REDEFINE: %{cflags} = -triple x86_64-unknown-linux-gnu -fopenmp-simd
718+
; REDEFINE: %{fcflags} = -check-prefix=SIMD
719+
; RUN: %{check}
720+
721+
; REDEFINE: %{cflags} = -triple x86_64-apple-darwin10.6.0
722+
; REDEFINE: %{fcflags} = -check-prefix=NO-SIMD
723+
; RUN: %{check}
724+
725+
; REDEFINE: %{cflags} = -triple x86_64-unknown-linux-gnu
726+
; REDEFINE: %{fcflags} = -check-prefix=NO-SIMD
727+
; RUN: %{check}
728+
729+
Besides providing initial values, the initial ``DEFINE:`` directives for the
730+
parameter substitutions in the above example serve a second purpose: they
731+
establish the substitution order so that both ``%{check}`` and its parameters
732+
expand as desired. There's a simple way to remember the required definition
733+
order in a test file: define a substitution before any substitution that might
734+
refer to it.
735+
736+
In general, substitution expansion behaves as follows:
737+
738+
- Upon arriving at each ``RUN:`` line, lit expands all substitutions in that
739+
``RUN:`` line using their current values from the substitution list. No
740+
substitution expansion is performed immediately at ``DEFINE:`` and
741+
``REDEFINE:`` directives except ``%(line)``, ``%(line+<number>)``, and
742+
``%(line-<number>)``.
743+
- When expanding substitutions in a ``RUN:`` line, lit makes only one pass
744+
through the substitution list by default. In this case, a substitution must
745+
have been inserted earlier in the substitution list than any substitution
746+
appearing in its value in order for the latter to expand. (For greater
747+
flexibility, you can enable multiple passes through the substitution list by
748+
setting `recursiveExpansionLimit`_ in a lit configuration file.)
749+
- While lit configuration files can insert anywhere in the substitution list,
750+
the insertion behavior of the ``DEFINE:`` and ``REDEFINE:`` directives is
751+
specified below and is designed specifically for the use case presented in the
752+
example above.
753+
- Defining a substitution in terms of itself, whether directly or via other
754+
substitutions, should be avoided. It usually produces an infinitely recursive
755+
definition that cannot be fully expanded. It does *not* define the
756+
substitution in terms of its previous value, even when using ``REDEFINE:``.
757+
758+
The relationship between the ``DEFINE:`` and ``REDEFINE:`` directive is
759+
analogous to the relationship between a variable declaration and variable
760+
assignment in many programming languages:
761+
762+
- ``DEFINE: %{name} = value``
763+
764+
This directive assigns the specified value to a new substitution whose
765+
pattern is ``%{name}``, or it reports an error if there is already a
766+
substitution whose pattern contains ``%{name}`` because that could produce
767+
confusing expansions (e.g., a lit configuration file might define a
768+
substitution with the pattern ``%{name}\[0\]``). The new substitution is
769+
inserted at the start of the substitution list so that it will expand first.
770+
Thus, its value can contain any substitution previously defined, whether in
771+
the same test file or in a lit configuration file, and both will expand.
772+
773+
- ``REDEFINE: %{name} = value``
774+
775+
This directive assigns the specified value to an existing substitution whose
776+
pattern is ``%{name}``, or it reports an error if there are no substitutions
777+
with that pattern or if there are multiple substitutions whose patterns
778+
contain ``%{name}``. The substitution's current position in the substitution
779+
list does not change so that expansion order relative to other existing
780+
substitutions is preserved.
781+
782+
The following properties apply to both the ``DEFINE:`` and ``REDEFINE:``
783+
directives:
784+
785+
- **Substitution name**: In the directive, whitespace immediately before or
786+
after ``%{name}`` is optional and discarded. ``%{name}`` must start with
787+
``%{``, it must end with ``}``, and the rest must start with a letter or
788+
underscore and contain only alphanumeric characters, hyphens, underscores, and
789+
colons. This syntax has a few advantages:
790+
791+
- It is impossible for ``%{name}`` to contain sequences that are special in
792+
python's ``re.sub`` patterns. Otherwise, attempting to specify
793+
``%{name}`` as a substitution pattern in a lit configuration file could
794+
produce confusing expansions.
795+
- The braces help avoid the possibility that another substitution's pattern
796+
will match part of ``%{name}`` or vice-versa, producing confusing
797+
expansions. However, the patterns of substitutions defined by lit
798+
configuration files and by lit itself are not restricted to this form, so
799+
overlaps are still theoretically possible.
800+
801+
- **Substitution value**: The value includes all text from the first
802+
non-whitespace character after ``=`` to the last non-whitespace character. If
803+
there is no non-whitespace character after ``=``, the value is the empty
804+
string. Escape sequences that can appear in python ``re.sub`` replacement
805+
strings are treated as plain text in the value.
806+
- **Line continuations**: If the last non-whitespace character on the line after
807+
``:`` is ``\``, then the next directive must use the same directive keyword
808+
(e.g., ``DEFINE:``) , and it is an error if there is no additional directive.
809+
That directive serves as a continuation. That is, before following the rules
810+
above to parse the text after ``:`` in either directive, lit joins that text
811+
together to form a single directive, replaces the ``\`` with a single space,
812+
and removes any other whitespace that is now adjacent to that space. A
813+
continuation can be continued in the same manner. A continuation containing
814+
only whitespace after its ``:`` is an error.
815+
816+
.. _recursiveExpansionLimit:
817+
818+
**recursiveExpansionLimit:**
819+
820+
As described in the previous section, when expanding substitutions in a ``RUN:``
821+
line, lit makes only one pass through the substitution list by default. Thus,
822+
if substitutions are not defined in the proper order, some will remain in the
823+
``RUN:`` line unexpanded. For example, the following directives refer to
824+
``%{inner}`` within ``%{outer}`` but do not define ``%{inner}`` until after
825+
``%{outer}``:
826+
827+
.. code-block:: llvm
828+
829+
; By default, this definition order does not enable full expansion.
830+
831+
; DEFINE: %{outer} = %{inner}
832+
; DEFINE: %{inner} = expanded
833+
834+
; RUN: echo '%{outer}'
835+
836+
``DEFINE:`` inserts substitutions at the start of the substitution list, so
837+
``%{inner}`` expands first but has no effect because the original ``RUN:`` line
838+
does not contain ``%{inner}``. Next, ``%{outer}`` expands, and the output of
839+
the ``echo`` command becomes:
840+
841+
.. code-block:: shell
842+
843+
%{inner}
844+
845+
Of course, one way to fix this simple case is to reverse the definitions of
846+
``%{outer}`` and ``%{inner}``. However, if a test has a complex set of
847+
substitutions that can all reference each other, there might not exist a
848+
sufficient substitution order.
849+
850+
To address such use cases, lit configuration files support
851+
``config.recursiveExpansionLimit``, which can be set to a non-negative integer
852+
to specify the maximum number of passes through the substitution list. Thus, in
853+
the above example, setting the limit to 2 would cause lit to make a second pass
854+
that expands ``%{inner}`` in the ``RUN:`` line, and the output from the ``echo``
855+
command when then be:
856+
857+
.. code-block:: shell
858+
859+
expanded
860+
861+
To improve performance, lit will stop making passes when it notices the ``RUN:``
862+
line has stopped changing. In the above example, setting the limit higher than
863+
2 is thus harmless.
674864

865+
To facilitate debugging, after reaching the limit, lit will make one extra pass
866+
and report an error if the ``RUN:`` line changes again. In the above example,
867+
setting the limit to 1 will thus cause lit to report an error instead of
868+
producing incorrect output.
675869

676870
Options
677871
-------

llvm/test/tools/llvm-cvtres/help.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; HELP_TEST: OVERVIEW: Resource Converter
55
; HELP_TEST-DAG: USAGE: llvm-cvtres [options] file...
66
; HELP_TEST-DAG: OPTIONS:
7-
; HELP_TEST-NEXT: /DEFINE:symbol Not implemented
7+
; HELP_TEST-NEXT: /{{DEFINE}}:symbol Not implemented
88
; HELP_TEST-NEXT: /FOLDDUPS: Not implemented
99
; HELP_TEST-NEXT: /HELP Display available options
1010
; HELP_TEST-NEXT: /MACHINE:{ARM|ARM64|EBC|IA64|X64|X86}

0 commit comments

Comments
 (0)