Index: llvm/include/llvm/Support/Errno.h =================================================================== --- llvm/include/llvm/Support/Errno.h +++ llvm/include/llvm/Support/Errno.h @@ -34,9 +34,10 @@ inline auto RetryAfterSignal(const FailT &Fail, const Fun &F, const Args &... As) -> decltype(F(As...)) { decltype(F(As...)) Res; - do + do { + errno = 0; Res = F(As...); - while (Res == Fail && errno == EINTR); + } while (Res == Fail && errno == EINTR); return Res; } Index: llvm/unittests/Support/ErrnoTest.cpp =================================================================== --- llvm/unittests/Support/ErrnoTest.cpp +++ llvm/unittests/Support/ErrnoTest.cpp @@ -33,4 +33,7 @@ std::unique_ptr P(RetryAfterSignal(nullptr, [] { return new int(47); })); EXPECT_EQ(47, *P); + + errno = EINTR; + EXPECT_EQ(-1, RetryAfterSignal(-1, [] { return -1; })); }