[Sanitizer] Allow runtime flags be separated by colon as well as space
authorAlexey Samsonov <samsonov@google.com>
Tue, 19 Feb 2013 13:03:37 +0000 (13:03 +0000)
committerAlexey Samsonov <samsonov@google.com>
Tue, 19 Feb 2013 13:03:37 +0000 (13:03 +0000)
llvm-svn: 175511

compiler-rt/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc

index eca910c..2ef4278 100644 (file)
@@ -38,7 +38,8 @@ static bool GetFlagValue(const char *env, const char *name,
       pos += 1;
       end = internal_strchr(pos, '\'');
     } else {
-      end = internal_strchr(pos, ' ');
+      // Read until the next space or colon.
+      end = pos + internal_strcspn(pos, " :");
     }
     if (end == 0)
       end = pos + internal_strlen(pos);
index c0589f4..8c456c6 100644 (file)
@@ -32,7 +32,7 @@ static void TestStrFlag(const char *start_value, const char *env,
                         const char *final_value) {
   const char *flag = start_value;
   ParseFlag(env, &flag, kFlagName);
-  EXPECT_EQ(internal_strcmp(final_value, flag), 0);
+  EXPECT_EQ(0, internal_strcmp(final_value, flag));
 }
 
 TEST(SanitizerCommon, BooleanFlags) {
@@ -65,4 +65,21 @@ TEST(SanitizerCommon, StrFlags) {
   TestStrFlag("", "--flag_name=\"abc qwe\" asd", "abc qwe");
 }
 
+static void TestTwoFlags(const char *env, bool expected_flag1,
+                         const char *expected_flag2) {
+  bool flag1 = !expected_flag1;
+  const char *flag2 = "";
+  ParseFlag(env, &flag1, "flag1");
+  ParseFlag(env, &flag2, "flag2");
+  EXPECT_EQ(expected_flag1, flag1);
+  EXPECT_EQ(0, internal_strcmp(flag2, expected_flag2));
+}
+
+TEST(SanitizerCommon, MultipleFlags) {
+  TestTwoFlags("flag1=1 flag2='zzz'", true, "zzz");
+  TestTwoFlags("flag2='qxx' flag1=0", false, "qxx");
+  TestTwoFlags("flag1=false:flag2='zzz'", false, "zzz");
+  TestTwoFlags("flag2=qxx:flag1=yes", true, "qxx");
+}
+
 }  // namespace __sanitizer