<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55045>55045</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [CL] Incorrect handling in auto-suggested command line arguments
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            tools:opt,
            llvm:core
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          tsymalla
      </td>
    </tr>
</table>

<pre>
    Hi,

whenever you are providing an incorrect option to a command-line tool, the CL framework tries to find a possible suggestion by calculating the smallest edit distance.

The framework tries to append the RHS of the argument the user passed in. However, this leads in some cases to an incorrect argument string suggested.

See for instance this argument:
-print-after-last=instcombine

This suggests:
Did you mean '--print-after-all=instcombine'?

However, this is wrong, as print-after-all only accepts boolean arguments.

This would be easy to do if there would be a way to access the parser being wrapped inside the cl::opt. Unfortunately, you can only access the Option instance itself. Still, the parser is templatized, so this is not too straight-forward even if it seems easy at first glance. I could think of following solution:

- Create some global objects for each parser specialization, possibly store callbacks  to the specific parse() calls somewhere
- Host a map with Options* to strings, these strings represent the types (the values returned by getValueName() (string, int, ...))
- When instantiating the cl::opt, save the Option* and the stringified type
- At runtime, when calculating the nearest option, find the specific parser instance / callback and call it

However, this would still require a way to work around the templatized Value reference argument in parse() - we don't want to have any value assigned when just checking if the argument value that the CL framework suggests is valid.

>From a high-level, fixing this would require a way to match the argument values against types defined in the cl::opt and to find if an option would suggest a specific value. However, LLVM  doesn't store the cl::opt somewhere, so accessing the parser is not possible from the outside.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9Vk1v4zYQ_TXyZWDBka18HHzIJgiyQNoCTbt7HkljiRtK1JJUVO-v7wwpKY5dFDAsSxRn3rx58-jCVMf9s0qyh2TzmGzu4_fYUEfvZOFoBkBL0FvzrirV1YAdqK401lLpwfRemQ68AYTStC121VqrjviJ0RwTfEPw8AIHi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