-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc][test] remove C++ stdlib includes #122369
Conversation
These make cross compiling the test suite more difficult, as you need the sysroot to contain these headers and libraries cross compiled for your target. It's straightforward to stick with the corresponding C headers.
@llvm/pr-subscribers-libc Author: Nick Desaulniers (nickdesaulniers) ChangesThese make cross compiling the test suite more difficult, as you need the Full diff: https://github.com/llvm/llvm-project/pull/122369.diff 3 Files Affected:
diff --git a/libc/test/UnitTest/ExecuteFunctionUnix.cpp b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
index 3a657c00851c7b..df71738668592a 100644
--- a/libc/test/UnitTest/ExecuteFunctionUnix.cpp
+++ b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
@@ -8,13 +8,13 @@
#include "ExecuteFunction.h"
#include "src/__support/macros/config.h"
-#include <cassert>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <memory>
+#include "test/UnitTest/ExecuteFunction.h" // FunctionCaller
+#include <assert.h>
#include <poll.h>
#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -35,21 +35,20 @@ int ProcessStatus::get_fatal_signal() {
}
ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) {
- std::unique_ptr<FunctionCaller> X(func);
int pipe_fds[2];
if (::pipe(pipe_fds) == -1)
return ProcessStatus::error("pipe(2) failed");
// Don't copy the buffers into the child process and print twice.
- std::cout.flush();
- std::cerr.flush();
+ ::fflush(stderr);
+ ::fflush(stdout);
pid_t pid = ::fork();
if (pid == -1)
return ProcessStatus::error("fork(2) failed");
if (!pid) {
(*func)();
- std::exit(0);
+ ::exit(0);
}
::close(pipe_fds[1]);
diff --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp
index 37ba0a0a7abde4..889f9f6f44a913 100644
--- a/libc/test/UnitTest/FPExceptMatcher.cpp
+++ b/libc/test/UnitTest/FPExceptMatcher.cpp
@@ -9,11 +9,11 @@
#include "FPExceptMatcher.h"
#include "src/__support/macros/config.h"
+#include "test/UnitTest/ExecuteFunction.h" // FunctionCaller
#include "test/UnitTest/Test.h"
#include "hdr/types/fenv_t.h"
#include "src/__support/FPUtil/FEnvImpl.h"
-#include <memory>
#include <setjmp.h>
#include <signal.h>
@@ -37,14 +37,13 @@ static void sigfpeHandler(int sig) {
}
FPExceptMatcher::FPExceptMatcher(FunctionCaller *func) {
- auto oldSIGFPEHandler = signal(SIGFPE, &sigfpeHandler);
- std::unique_ptr<FunctionCaller> funcUP(func);
+ sighandler_t oldSIGFPEHandler = signal(SIGFPE, &sigfpeHandler);
caughtExcept = false;
fenv_t oldEnv;
fputil::get_env(&oldEnv);
if (sigsetjmp(jumpBuffer, 1) == 0)
- funcUP->call();
+ func->call();
// We restore the previous floating point environment after
// the call to the function which can potentially raise SIGFPE.
fputil::set_env(&oldEnv);
diff --git a/libc/test/UnitTest/LibcDeathTestExecutors.cpp b/libc/test/UnitTest/LibcDeathTestExecutors.cpp
index 77b0559c7acea9..943e2c23c5fde9 100644
--- a/libc/test/UnitTest/LibcDeathTestExecutors.cpp
+++ b/libc/test/UnitTest/LibcDeathTestExecutors.cpp
@@ -12,7 +12,7 @@
#include "test/UnitTest/ExecuteFunction.h"
#include "test/UnitTest/TestLogger.h"
-#include <cassert>
+#include <assert.h>
namespace {
constexpr unsigned TIMEOUT_MS = 10000;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, though in future we should look into using our own functions in ExecuteFunctionUnix.cpp
. I think we have most of what's needed now.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/13525 Here is the relevant piece of the build log for the reference
|
ah, that's why they were using std::unique_ptr. I guess I can manually free these callbacks. |
Looks like the smart pointer I removed was being used to free the underlying object. Fixes: llvm#122369
#122378 should fix this |
Looks like the smart pointer I removed was being used to free the underlying object. Fixes: #122369
These were created with operator new (see `Test::createCallable`), so operator delete should be used instead of free(). Fixes: llvm#122369 Fixes: llvm#122378
These make cross compiling the test suite more difficult, as you need the
sysroot to contain these headers and libraries cross compiled for your target.
It's straightforward to stick with the corresponding C headers.