Equivalent to the changes made in https://github.com/llvm/llvm-project/pull/83941, except to support shell tests.