From: Alexander Lanin Date: Fri, 2 Oct 2020 20:04:12 +0000 (+0200) Subject: refactor: Simplify logic of -x handling X-Git-Tag: v4.0~40^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F678%2Fhead;p=thirdparty%2Fccache.git refactor: Simplify logic of -x handling --- diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 86b96a10f..c3593e6de 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -389,33 +389,35 @@ process_arg(Context& ctx, return nullopt; } - if (args[i].length() >= 3 && Util::starts_with(args[i], "-x") - && !islower(args[i][2])) { - // -xCODE (where CODE can be e.g. Host or CORE-AVX2, always starting with an - // uppercase letter) is an ordinary Intel compiler option, not a language - // specification. (GCC's "-x" language argument is always lowercase.) - state.common_args.push_back(args[i]); - return nullopt; - } - - // Special handling for -x: remember the last specified language before the - // input file and strip all -x options from the arguments. - if (args[i] == "-x") { - if (i == args.size() - 1) { - log("Missing argument to {}", args[i]); - return Statistic::bad_compiler_arguments; + if (Util::starts_with(args[i], "-x")) { + if (args[i].length() >= 3 && !islower(args[i][2])) { + // -xCODE (where CODE can be e.g. Host or CORE-AVX2, always starting with + // an uppercase letter) is an ordinary Intel compiler option, not a + // language specification. (GCC's "-x" language argument is always + // lowercase.) + state.common_args.push_back(args[i]); + return nullopt; } - if (args_info.input_file.empty()) { - state.explicit_language = args[i + 1]; + + // Special handling for -x: remember the last specified language before the + // input file and strip all -x options from the arguments. + if (args[i].length() == 2) { + if (i == args.size() - 1) { + log("Missing argument to {}", args[i]); + return Statistic::bad_compiler_arguments; + } + if (args_info.input_file.empty()) { + state.explicit_language = args[i + 1]; + } + i++; + return nullopt; } - i++; - return nullopt; - } - if (Util::starts_with(args[i], "-x")) { - if (args_info.input_file.empty()) { - state.explicit_language = args[i].substr(2); + if (args[i].length() >= 3) { + if (args_info.input_file.empty()) { + state.explicit_language = args[i].substr(2); + } + return nullopt; } - return nullopt; } // We need to work out where the output was meant to go.