[llvm] r211260 - CommandLine: bail out when options get multiply registered

David Blaikie dblaikie at gmail.com
Thu Jun 19 07:23:35 PDT 2014


On Thu, Jun 19, 2014 at 12:25 AM, Alp Toker <alp at nuanti.com> wrote:
> Author: alp
> Date: Thu Jun 19 02:25:25 2014
> New Revision: 211260
>
> URL: http://llvm.org/viewvc/llvm-project?rev=211260&view=rev
> Log:
> CommandLine: bail out when options get multiply registered
>
> These errors are strictly unrecoverable and indicate serious issues such as
> conflicting option names or an incorrectly linked LLVM distribution.
>
> With this change, the errors actually get detected so tests don't pass
> silently.
>
> Modified:
>     llvm/trunk/lib/Support/CommandLine.cpp
>
> Modified: llvm/trunk/lib/Support/CommandLine.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=211260&r1=211259&r2=211260&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/CommandLine.cpp (original)
> +++ llvm/trunk/lib/Support/CommandLine.cpp Thu Jun 19 02:25:25 2014
> @@ -145,6 +145,7 @@ void OptionCategory::registerCategory()
>  static void GetOptionInfo(SmallVectorImpl<Option*> &PositionalOpts,
>                            SmallVectorImpl<Option*> &SinkOpts,
>                            StringMap<Option*> &OptionsMap) {
> +  bool HadErrors = false;
>    SmallVector<const char*, 16> 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(SmallVectorImp
>      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;

Is there any reason to use the flag and defer the fatal error until
later rather than just calling it directly here (and in the other case
below)?

>        }
>      }
>
> @@ -171,8 +173,10 @@ static void GetOptionInfo(SmallVectorImp
>      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(SmallVectorImp
>
>    // 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");
>  }
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list