check for regex errors
authorMiodrag Milanovic <mmicko@gmail.com>
Thu, 20 Feb 2020 10:41:37 +0000 (11:41 +0100)
committerMiodrag Milanovic <mmicko@gmail.com>
Thu, 20 Feb 2020 10:41:37 +0000 (11:41 +0100)
passes/cmds/logger.cc

index 947b178c50cc1c8d91b66336d0e32b41af262540..3abe4e93b90a9972566fab84ca24006c2109c13c 100644 (file)
@@ -151,22 +151,26 @@ struct LoggerPass : public Pass {
                                if (type=="error" && count!=1)
                                        log_cmd_error("Expected error message occurrences must be 1 !\n");
                                log("Added regex '%s' for warnings to expected %s list.\n", pattern.c_str(), type.c_str());
-                               if (type=="error")
-                                       log_expect_error.push_back(std::make_pair(std::regex(pattern,
-                                               std::regex_constants::nosubs |
-                                               std::regex_constants::optimize |
-                                               std::regex_constants::egrep), LogExpectedItem(pattern, count)));
-                               else if (type=="warning")
-                                       log_expect_warning.push_back(std::make_pair(std::regex(pattern,
-                                               std::regex_constants::nosubs |
-                                               std::regex_constants::optimize |
-                                               std::regex_constants::egrep), LogExpectedItem(pattern, count)));
-                               else
-                                       log_expect_log.push_back(std::make_pair(std::regex(pattern,
-                                               std::regex_constants::nosubs |
-                                               std::regex_constants::optimize |
-                                               std::regex_constants::egrep), LogExpectedItem(pattern, count)));
-
+                               try {
+                                       if (type=="error")
+                                               log_expect_error.push_back(std::make_pair(std::regex(pattern,
+                                                       std::regex_constants::nosubs |
+                                                       std::regex_constants::optimize |
+                                                       std::regex_constants::egrep), LogExpectedItem(pattern, count)));
+                                       else if (type=="warning")
+                                               log_expect_warning.push_back(std::make_pair(std::regex(pattern,
+                                                       std::regex_constants::nosubs |
+                                                       std::regex_constants::optimize |
+                                                       std::regex_constants::egrep), LogExpectedItem(pattern, count)));
+                                       else
+                                               log_expect_log.push_back(std::make_pair(std::regex(pattern,
+                                                       std::regex_constants::nosubs |
+                                                       std::regex_constants::optimize |
+                                                       std::regex_constants::egrep), LogExpectedItem(pattern, count)));
+                               }
+                               catch (const std::regex_error& e) {
+                                       log_cmd_error("Error in regex expression '%s' !\n", pattern.c_str());
+                               }
                                continue;
                        }
                        if (args[argidx] == "-expect-no-warnings") {