Process moer options when processing options file. (#2251)
When processing options in a file, it does have access to the
ValidatorOptions and OptimizerOptions object, so options that change
those do not work. We just need to pass it in.
Fixes #2219.
diff --git a/test/tools/opt/oconfig.py b/test/tools/opt/oconfig.py
index 3372379..899d93e 100644
--- a/test/tools/opt/oconfig.py
+++ b/test/tools/opt/oconfig.py
@@ -56,3 +56,18 @@
--loop-unroll
""", '.cfg')
spirv_args = [shader, '-o', placeholder.TempFileName('output.spv'), config]
+
+@inside_spirv_testsuite('SpirvOptConfigFile')
+class TestOconfigComments(expect.SuccessfulReturn):
+ """Tests empty config files are accepted.
+
+ https://github.com/KhronosGroup/SPIRV-Tools/issues/1778
+ """
+
+ shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm')
+ config = placeholder.ConfigFlagsFile("""
+# This is a comment.
+-O
+--relax-struct-store
+""", '.cfg')
+ spirv_args = [shader, '-o', placeholder.TempFileName('output.spv'), config]
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 106832c..db056b1 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -447,12 +447,15 @@
// Parses and handles the -Oconfig flag. |prog_name| contains the name of
// the spirv-opt binary (used to build a new argv vector for the recursive
// invocation to ParseFlags). |opt_flag| contains the -Oconfig=FILENAME flag.
-// |optimizer|, |in_file| and |out_file| are as in ParseFlags.
+// |optimizer|, |in_file|, |out_file|, |validator_options|, and
+// |optimizer_options| are as in ParseFlags.
//
// This returns the same OptStatus instance returned by ParseFlags.
OptStatus ParseOconfigFlag(const char* prog_name, const char* opt_flag,
spvtools::Optimizer* optimizer, const char** in_file,
- const char** out_file) {
+ const char** out_file,
+ spvtools::ValidatorOptions* validator_options,
+ spvtools::OptimizerOptions* optimizer_options) {
std::vector<std::string> flags;
flags.push_back(prog_name);
@@ -476,7 +479,7 @@
}
return ParseFlags(static_cast<int>(flags.size()), new_argv, optimizer,
- in_file, out_file, nullptr, nullptr);
+ in_file, out_file, validator_options, optimizer_options);
}
// Canonicalize the flag in |argv[argi]| of the form '--pass arg' into
@@ -563,7 +566,8 @@
}
} else if (0 == strncmp(cur_arg, "-Oconfig=", sizeof("-Oconfig=") - 1)) {
OptStatus status =
- ParseOconfigFlag(argv[0], cur_arg, optimizer, in_file, out_file);
+ ParseOconfigFlag(argv[0], cur_arg, optimizer, in_file, out_file,
+ validator_options, optimizer_options);
if (status.action != OPT_CONTINUE) {
return status;
}