X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FCommandLine.cpp;h=4c1df5c47dd544f497be52c3f6cc57d898eca9f6;hb=6d48faf334248edd0cf0933b86aee87dda2fbee8;hp=e09d4b6e47b4fc0a37b3ec68c579b68b91f6d804;hpb=d0dbed10d5f08aa3efa31af7287e4c1b34735c57;p=oota-llvm.git diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index e09d4b6e47b..4c1df5c47dd 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -145,6 +145,7 @@ void OptionCategory::registerCategory() { static void GetOptionInfo(SmallVectorImpl &PositionalOpts, SmallVectorImpl &SinkOpts, StringMap &OptionsMap) { + bool HadErrors = false; SmallVector OptionNames; Option *CAOpt = nullptr; // The ConsumeAfter option if it exists. for (Option *O = RegisteredOptionList; O; O = O->getNextRegisteredOption()) { @@ -158,8 +159,9 @@ static void GetOptionInfo(SmallVectorImpl &PositionalOpts, for (size_t i = 0, e = OptionNames.size(); i != e; ++i) { // Add argument to the argument map! if (OptionsMap.GetOrCreateValue(OptionNames[i], O).second != O) { - errs() << ProgramName << ": CommandLine Error: Argument '" - << OptionNames[i] << "' defined more than once!\n"; + errs() << ProgramName << ": CommandLine Error: Option '" + << OptionNames[i] << "' registered more than once!\n"; + HadErrors = true; } } @@ -171,8 +173,10 @@ static void GetOptionInfo(SmallVectorImpl &PositionalOpts, else if (O->getMiscFlags() & cl::Sink) // Remember sink options SinkOpts.push_back(O); else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) { - if (CAOpt) + if (CAOpt) { O->error("Cannot specify more than one option with cl::ConsumeAfter!"); + HadErrors = true; + } CAOpt = O; } } @@ -182,6 +186,12 @@ static void GetOptionInfo(SmallVectorImpl &PositionalOpts, // Make sure that they are in order of registration not backwards. std::reverse(PositionalOpts.begin(), PositionalOpts.end()); + + // Fail hard if there were errors. These are strictly unrecoverable and + // indicate serious issues such as conflicting option names or an incorrectly + // linked LLVM distribution. + if (HadErrors) + report_fatal_error("inconsistency in registered CommandLine options"); } @@ -621,13 +631,15 @@ void cl::TokenizeWindowsCommandLine(StringRef Src, StringSaver &Saver, static bool ExpandResponseFile(const char *FName, StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl &NewArgv) { - std::unique_ptr MemBuf; - if (MemoryBuffer::getFile(FName, MemBuf)) + ErrorOr> MemBufOrErr = + MemoryBuffer::getFile(FName); + if (!MemBufOrErr) return false; - StringRef Str(MemBuf->getBufferStart(), MemBuf->getBufferSize()); + MemoryBuffer &MemBuf = *MemBufOrErr.get(); + StringRef Str(MemBuf.getBufferStart(), MemBuf.getBufferSize()); // If we have a UTF-16 byte order mark, convert to UTF-8 for parsing. - ArrayRef BufRef(MemBuf->getBufferStart(), MemBuf->getBufferEnd()); + ArrayRef BufRef(MemBuf.getBufferStart(), MemBuf.getBufferEnd()); std::string UTF8Buf; if (hasUTF16ByteOrderMark(BufRef)) { if (!convertUTF16ToUTF8String(BufRef, UTF8Buf)) @@ -1006,13 +1018,12 @@ void cl::ParseCommandLineOptions(int argc, const char * const *argv, } // Loop over args and make sure all required args are specified! - for (StringMap::iterator I = Opts.begin(), - E = Opts.end(); I != E; ++I) { - switch (I->second->getNumOccurrencesFlag()) { + for (const auto &Opt : Opts) { + switch (Opt.second->getNumOccurrencesFlag()) { case Required: case OneOrMore: - if (I->second->getNumOccurrences() == 0) { - I->second->error("must be specified at least once!"); + if (Opt.second->getNumOccurrences() == 0) { + Opt.second->error("must be specified at least once!"); ErrorParsing = true; } // Fall through