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

    <tr>
        <th>Summary</th>
        <td>
            Checking for conflicts before registering synthetic child providers/filters doesn't work correctly with regex
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lldb
      </td>
    </tr>

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

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

<pre>
    `CommandObjectTypeSynthAdd::AddSynth` has some code to check for conflicting filters in the same category (there's a symmetric check for conflicting synth providers when adding a new filter, but let's focus on only one case). The check looks like this:

```c++
  if (category->AnyMatches(type_name, eFormatCategoryItemFilter, false)) {
    if (error)
      error->SetErrorStringWithFormat("cannot add synthetic for type %s when "
                                      "filter is defined in same category!",
                                      type_name.AsCString());
    return false;
  }
```

The important detail here is that `type_name` can actually be either a type name **or a regex** (if using `type synthetic add -x`). However, `category->AnyMatches` always treats `type_name` as a type name, and will try to match a regex string against other regex strings, which is not correct.

For example, this is lldb working correctly and rejecting a conflicting formatter.
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> class my_child_provider:
...   pass
... 
>>> ^D
now exiting InteractiveConsole...
(lldb) type synthetic add -l my_child_provider whatever
(lldb) type filter add --child a whatever
error: cannot add filter for type whatever when synthetic is defined in same category!
```

However, if we use regex it will happily accept conflicting formatters:
```
(lldb) type synthetic add -l my_child_provider -x "^whatever$"
(lldb) type filter add --child a -x "^whatever$"
(lldb) 
```
because the string "^whatever$" is not matched by the regex "^whatever$".

We can also make it fail the other way around, and make it incorrectly reject non-conflicting formatters. For example:
```
(lldb) type synthetic add -l my_child_provider -x "^MyType\[[0-9]+]$"
(lldb) type filter add --child a -x "MyType[12]"
error: cannot add filter for type MyType[12] when synthetic is defined in same category!
```
In this case, `"^MyType\[[0-9]+]$"` would accept types that look like an array of `MyType`, and `"MyType[12]"` _looks_ like an array, but it would actually match `MyType1` and `MyType2` so there's no conflict.

I think the right thing to do is to just skip this check when adding a regex-based filter. I'll prepare a patch.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1VltvozgU_jXkxQoikOsDD2naavsw2pVaaR4rAyZ4YmzWNk3593uODYRMU01ntVtZKRj7XL7znUumii4N1tFB1TWVxZ_ZD5bbl65hz5201b4ogmQPCx7cBpwkFTXEqJqRXBWMWEXyiuUnUioNO7IUPLdcHknJhWXaEC6JrRgxFG9Qy45KdySIt7CpWRBvDKHEdHXNrOb5J7IM6iaNVm-8QJnniklCiwK_USLZudcWxAeStZYIZp3kUuWtIUrCEh38oAUGlO5C8gI2eWVCqZMhgp_AmYobdDi6D6Lhdx35lQfxHS63Swgv0YnBoXmQPOxl941akGnQO4DwVYLPaBJ7VLqm9tAffrKsfhztLalwJsEiwWaUP2hgWiuNn8d9Qtweqnxm9gGfnwE7efzObeU1wb0gjnMqpbKIkweQWQAYoUXjQPaqBxKOTqX_6g-Oe7QJN6RgJZeswChfRTiIFyg2PvyO5BG0cG8O3ifnCWITJBNoNLOtlj10lw_B5v6noE0jiRHndaO0pdKC4ZZyQZCE6IetqCVw4RI3YDoASGhuWyqAPRkjjCNpgXEOQDwFYOxhKdzU7Mje_TsGDsLXGiRoL3USA4zI_B3NQyb-oc7szXMBaXabUWANFWfagaWaUWs-2ErN1C4UBulMzlwIuNFhmtYoarCTGAcvoUfKpbFEOc-mnwzKOFcc7gA-SKRcaQ3VIZyCCnwj7J3WjXA6MYHwuBBFRs5Kn1BHfw8wRJM0wxLjM_eqXjjmAq3C2zGMtygUs8TkmjfWb__V2Qry-0nCRQgVf2P-uQGKgCjyosA8bp1tnvWbv1tuB1ptHOrxxp_p9wj4dLBazO8HU5IHv0guqDGk7l7ziovidahIY80IwxDo2cChy_vPMoLVQ09Tqc7OOnR_4sFBSaMEg7sfXL9FJPHRHogb0AhJdVNAn77u9tzdhFhcX_F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