From c6b23f823750fed58945ed0a47e1d65d9db92fd2 Mon Sep 17 00:00:00 2001 From: David Neto Date: Thu, 22 Sep 2016 17:09:34 -0400 Subject: [PATCH] Handle parse failure for setting spec constants --- tools/opt/opt.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 38a6c27..b317f8e 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -54,8 +54,8 @@ Options: when possible. --set-spec-const-default-value ": ..." Set the default values of the specialization constants with - - pairs specified in a double-quoted - string. - pairs must be separated by + : pairs specified in a double-quoted + string. : 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( std::move(*spec_ids_vals)); } else { fprintf(stderr, - "error: Expect a string of - pairs."); + "error: Expected a string of : pairs."); return 1; } } else if (0 == strcmp(cur_arg, "--freeze-spec-const")) { -- 2.7.4