[PATCH] D98859: [lit] Handle plain negations directly in the internal shell

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 31 22:45:55 PDT 2021


mstorsjo added a comment.

In D98859#2662417 <https://reviews.llvm.org/D98859#2662417>, @mstorsjo wrote:

> Adding a fake external for the 'not' executable is a bit tricky though... With the code as is, for a sequence of 'not not --crash <cmd>', it deduces that there's a '--crash' option in there, and chooses not to switch to the internal not for the outer invocation either.
>
> To fix that case, I'd have to change the code to peel off as many 'not' invocations from the top until the first one with a '--crash' option. Not sure if that's worth the extra complexity for the implementation - what do you think?

@jdenny - with this change to the functionality, I could add a fake-external `not` to to the tests, to make sure we always evaluate all the leading instances of `not`/`!` internally, up to the first `not --crash`:

  diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
  index fbb8e93058a2..8e07d09e8bd6 100644
  --- a/llvm/utils/lit/lit/TestRunner.py
  +++ b/llvm/utils/lit/lit/TestRunner.py
  @@ -708,16 +708,18 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
                                                   " subcommand")
               elif args[0] == 'not':
                   not_args.append(args.pop(0))
  -                not_count += 1
                   if args and args[0] == '--crash':
                       not_args.append(args.pop(0))
                       not_crash = True
  +                if not not_crash:
  +                    not_count += 1
                   if not args:
                       raise InternalShellError(j, "Error: 'not' requires a"
                                                   " subcommand")
               elif args[0] == '!':
                   not_args.append(args.pop(0))
  -                not_count += 1
  +                if not not_crash:
  +                    not_count += 1
                   if not args:
                       raise InternalShellError(j, "Error: '!' requires a"
                                                   " subcommand")
  @@ -769,13 +771,10 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
           # blindly pass along the status it receives from any command it calls.
           
           # For plain negations, either 'not' without '--crash', or the shell
  -        # operator '!', leave them out from the command to execute and
  -        # invert the result code afterwards.
  -        if not_crash:
  -            args = not_args + args
  -            not_count = 0                       
  -        else:
  -            not_args = []
  +        # operator '!' (counted via not_count), leave them out from the
  +        # command to execute and invert the result code afterwards.
  +        args = not_args[not_count:] + args
  +        not_args = []
          
           stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv,
                                                    opened_files)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98859/new/

https://reviews.llvm.org/D98859



More information about the llvm-commits mailing list