Handle parse failure for setting spec constants
authorDavid Neto <dneto@google.com>
Thu, 22 Sep 2016 21:09:34 +0000 (17:09 -0400)
committerDavid Neto <dneto@google.com>
Thu, 22 Sep 2016 21:45:56 +0000 (17:45 -0400)
tools/opt/opt.cpp

index 38a6c27..b317f8e 100644 (file)
@@ -54,8 +54,8 @@ Options:
                when possible.
   --set-spec-const-default-value "<spec id>:<default value> ..."
                Set the default values of the specialization constants with
-               <spec id>-<default value> pairs specified in a double-quoted
-               string. <spec id>-<default value> pairs must be separated by
+               <spec id>:<default value> pairs specified in a double-quoted
+               string. <spec id>:<default value> pairs must be separated by
                blank spaces, and in each pair, spec id and default value must
                be separated with colon ':' without any blank spaces in between.
                e.g.: --set-spec-const-default-value "1:100 2:400"
@@ -103,11 +103,18 @@ int main(int argc, char** argv) {
           auto spec_ids_vals =
               opt::SetSpecConstantDefaultValuePass::ParseDefaultValuesString(
                   argv[argi]);
+          if (!spec_ids_vals) {
+            fprintf(stderr,
+                    "error: Invalid argument for "
+                    "--set-spec-const-default-value: %s\n",
+                    argv[argi]);
+            return 1;
+          }
           pass_manager.AddPass<opt::SetSpecConstantDefaultValuePass>(
               std::move(*spec_ids_vals));
         } else {
           fprintf(stderr,
-                  "error: Expect a string of <spec id>-<default value> pairs.");
+                  "error: Expected a string of <spec id>:<default value> pairs.");
           return 1;
         }
       } else if (0 == strcmp(cur_arg, "--freeze-spec-const")) {