diff --git a/CMakeLists.txt b/CMakeLists.txt
index 038139a2409..0f73da65365 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 90e5d327c75..69f1ed7bc14 100644
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -269,7 +269,7 @@ CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec
     "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
 
 check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC)
-if( LLVM_USING_GLIBC )
+if( LLVM_USING_GLIBC OR MSYS )
   add_definitions( -D_GNU_SOURCE )
   list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
 endif()
diff --git a/test/CodeGen/MIR/AArch64/lit.local.cfg b/test/CodeGen/MIR/AArch64/lit.local.cfg
index f4f77c5aa31..04f6c112bdd 100644
--- a/test/CodeGen/MIR/AArch64/lit.local.cfg
+++ b/test/CodeGen/MIR/AArch64/lit.local.cfg
@@ -4,5 +4,5 @@ if not 'AArch64' in config.root.targets:
     config.unsupported = True
 
 # For now we don't test arm64-win32.
-if re.search(r'cygwin|mingw32|win32|windows-gnu|windows-msvc', config.target_triple):
+if re.search(r'cygwin|mingw32|msys|win32|windows-gnu|windows-msvc', config.target_triple):
     config.unsupported = True
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
index 4eaa6cb77c8..dfac0215771 100644
--- a/test/lit.cfg.py
+++ b/test/lit.cfg.py
@@ -97,7 +97,7 @@ lli_args = []
 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
 # Windows.  FIXME: the process target triple should be used here, but this is
 # difficult to obtain on Windows.
-if re.search(r'cygwin|windows-gnu|windows-msvc', config.host_triple):
+if re.search(r'cygwin|msys|windows-gnu|windows-msvc', config.host_triple):
     lli_args = ['-mtriple=' + config.host_triple + '-elf']
 
 llc_args = []
diff --git a/tools/llvm-shlib/CMakeLists.txt b/tools/llvm-shlib/CMakeLists.txt
index f3a2056f80d..f1decd975d4 100644
--- a/tools/llvm-shlib/CMakeLists.txt
+++ b/tools/llvm-shlib/CMakeLists.txt
@@ -33,7 +33,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
   add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${INSTALL_WITH_TOOLCHAIN} ${SOURCES})
 
   list(REMOVE_DUPLICATES LIB_NAMES)
-  if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU)
+  if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) OR (MSYS)
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
