[Support] - Fix possible crash in match() of llvm::Regex.

Crash was possible if match() method
was called on object that was moved or object
created with empty constructor.

Testcases updated.

DIfferential revision: https://reviews.llvm.org/D24123

llvm-svn: 280473
diff --git a/llvm/unittests/Support/RegexTest.cpp b/llvm/unittests/Support/RegexTest.cpp
index 7b61a03..5e3ce39 100644
--- a/llvm/unittests/Support/RegexTest.cpp
+++ b/llvm/unittests/Support/RegexTest.cpp
@@ -151,6 +151,8 @@
   Regex r2("abc");
   r2 = std::move(r1);
   EXPECT_TRUE(r2.match("916"));
+  std::string Error;
+  EXPECT_FALSE(r1.isValid(Error));
 }
 
 TEST_F(RegexTest, NoArgConstructor) {
@@ -162,4 +164,11 @@
   EXPECT_TRUE(r1.isValid(Error));
 }
 
+TEST_F(RegexTest, MatchInvalid) {
+  Regex r1;
+  std::string Error;
+  EXPECT_FALSE(r1.isValid(Error));
+  EXPECT_FALSE(r1.match("X"));
+}
+
 }