Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Support/Windows/Program.inc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
llvm::append_range(EnvBlock, EnvString);
EnvBlock.push_back(0);
}
// If an empty environment (*Env is size zero), we need to
// terminate with two nulls.
if (Env->size() == 0)
EnvBlock.push_back(0);
EnvBlock.push_back(0);
}

Expand Down
18 changes: 18 additions & 0 deletions llvm/unittests/Support/ProgramTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,22 @@ TEST_F(ProgramEnvTest, TestExecuteWithNoStacktraceHandler) {
ASSERT_EQ(0, RetCode);
}

TEST_F(ProgramEnvTest, TestExecuteEmptyEnvironment) {
using namespace llvm::sys;

std::string Executable =
sys::fs::getMainExecutable(TestMainArgv0, &ProgramTestStringArg1);
StringRef argv[] = {
Executable,
"--gtest_filter=" // A null invocation to avoid infinite recursion
};

std::string Error;
bool ExecutionFailed;
int RetCode = ExecuteAndWait(Executable, argv, ArrayRef<StringRef>{}, {}, 0,
0, &Error, &ExecutionFailed);
EXPECT_FALSE(ExecutionFailed) << Error;
ASSERT_EQ(0, RetCode);
}

} // end anonymous namespace