summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDaniel Malea <daniel.malea@intel.com>2013-06-28 21:49:53 +0000
committerDaniel Malea <daniel.malea@intel.com>2013-06-28 21:49:53 +0000
commit9e638df937b66e4313445163e069623b72b86f9a (patch)
tree6b1d88a1957b212ec3f9762892e599425bd5fcd3 /unittests
parent40d8171e3e74f4786d89a8f1fb370653f81c7941 (diff)
downloadllvm-9e638df937b66e4313445163e069623b72b86f9a.tar.gz
llvm-9e638df937b66e4313445163e069623b72b86f9a.tar.bz2
llvm-9e638df937b66e4313445163e069623b72b86f9a.tar.xz
Fix Windows/Darwin build error in DebugIR unit tests
- mistakenly used get_current_dir() linux function - replaced with getcwd/_getcwd as appropriate for current platform git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185225 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Transforms/DebugIR/DebugIR.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/unittests/Transforms/DebugIR/DebugIR.cpp b/unittests/Transforms/DebugIR/DebugIR.cpp
index 978662a79d..cf81e7a728 100644
--- a/unittests/Transforms/DebugIR/DebugIR.cpp
+++ b/unittests/Transforms/DebugIR/DebugIR.cpp
@@ -32,6 +32,14 @@
#include "gtest/gtest.h"
+#if defined(LLVM_ON_WIN32)
+#include <direct.h>
+#define getcwd_impl _getcwd
+#elif defined (HAVE_GETCWD)
+#include <unistd.h>
+#define getcwd_impl getcwd
+#endif // LLVM_ON_WIN32
+
using namespace llvm;
using namespace std;
@@ -53,19 +61,21 @@ bool removeIfExists(StringRef Path) {
return existed;
}
+char * current_dir() {
+#if defined(LLVM_ON_WIN32) || defined(HAVE_GETCWD)
+ // calling getcwd (or _getcwd() on windows) with a null buffer makes it
+ // allocate a sufficiently sized buffer to store the current working dir.
+ return getcwd_impl(0, 0);
+#else
+ return 0;
+#endif
+}
+
class TestDebugIR : public ::testing::Test, public TrivialModuleBuilder {
protected:
TestDebugIR()
: TrivialModuleBuilder(sys::getProcessTriple())
-#ifdef HAVE_GETCWD
- ,
- cwd(get_current_dir_name())
-#else
- ,
- cwd(0)
-#endif
- {
- }
+ , cwd(current_dir()) {}
~TestDebugIR() { free(cwd); }