[all-commits] [llvm/llvm-project] 28412d: [lit] Implement DEFINE and REDEFINE directives

Joel E. Denny via All-commits all-commits at lists.llvm.org
Wed Sep 21 08:34:05 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 28412d1800e391c5ba8e7607bb15c74b106d581b
      https://github.com/llvm/llvm-project/commit/28412d1800e391c5ba8e7607bb15c74b106d581b
  Author: Joel E. Denny <jdenny.ornl at gmail.com>
  Date:   2022-09-21 (Wed, 21 Sep 2022)

  Changed paths:
    M clang/test/CodeGen/attr-noundef.cpp
    M clang/test/CodeGen/indirect-noundef.cpp
    M clang/test/Preprocessor/init.c
    M llvm/docs/CommandGuide/lit.rst
    M llvm/docs/TestingGuide.rst
    M llvm/test/tools/llvm-cvtres/help.test
    M llvm/test/tools/yaml2obj/ELF/custom-null-section.yaml
    M llvm/utils/lit/lit/TestRunner.py
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/before-name.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/between-name-equals.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-empty.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-dot.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-equals.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-newline.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-number.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/braces-with-ws.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/empty.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/no-equals.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/no-name.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/assignment/ws-only.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/empty.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/end-in-double-backslash.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define-bad-redefine.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define-continuation.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define-redefine.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define-run.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-define.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine-bad-define.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine-continuation.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine-define.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine-run.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-redefine.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-run-define.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/unterminated-run-redefine.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/continuation/ws-only.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-already-by-config.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-already-by-test.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-inside-pattern.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-multiple-exact.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-multiple-once-exact.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-prefixes-pattern.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/define-suffixes-pattern.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-inside-pattern.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-multiple-exact.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-multiple-once-exact.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-none.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-prefixes-pattern.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/defined-check/redefine-suffixes-pattern.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/location-range.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/errors/no-run.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/examples/param-subst.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/expansion-order.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/line-number-substitutions.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/lit.cfg
    A llvm/utils/lit/tests/Inputs/shtest-define/name-chars.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/recursiveExpansionLimit.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/shared-substs-0.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/shared-substs-1.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/value-equals.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/value-escaped.txt
    A llvm/utils/lit/tests/Inputs/shtest-define/ws-and-continuations.txt
    A llvm/utils/lit/tests/Inputs/shtest-shell/continuations.txt
    M llvm/utils/lit/tests/Inputs/testrunner-custom-parsers/test.txt
    A llvm/utils/lit/tests/shtest-define.py
    M llvm/utils/lit/tests/shtest-keyword-parse-errors.py
    M llvm/utils/lit/tests/shtest-shell.py
    M llvm/utils/lit/tests/unit/TestRunner.py

  Log Message:
  -----------
  [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




More information about the All-commits mailing list