<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - lit substitutions don't work well when a substitution is a prefix of another"
   href="https://llvm.org/bugs/show_bug.cgi?id=31237">31237</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lit substitutions don't work well when a substitution is a prefix of another
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Test Suite
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>lit
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dan@su-root.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>daniel@zuster.org, llvm-bugs@lists.llvm.org, modocache@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I was surprised to find today that lit was doing a substitution for me that I
wasn't expecting. It just so happened to be the "right thing" but this
behaviour could really bite us one day.

Concrete example:

Let's say we have

```
config.substitutions.append(('%klee', '/bin/klee'))
```

in our lit configuration file and we have a test that just contains

```
RUN: not echo %klee-stats
```

The test will fail with something like

```
******************** TEST 'KLEE :: regression/x.c' FAILED ********************
Script:
--
not /bin/klee-stats
--
Exit Code: 1
```

We can see that lit expanded the '%klee' in '%klee-stats'. Okay so I guess this
isn't too surprising but what if the lit configuration was this.

```
config.substitutions.append(('%klee', '/bin/klee'))
config.substitutions.append(('%klee-stats', '/bin/klee'))
```

then lit actually does the same thing it expands the RUN line to

```
not echo /bin/klee-stats
```

lit preferred the `%klee` substitution rather than the `%klee-stats` because it
is early in its list of substitutions than `%klee-stats`.

This might not be the behaviour that the user of lit expected.

I'm not sure the best way to handle this but I would suggest emitting a warning
if one of the user supplied substitutions is a prefix of another and the prefix
appears before the longer string in the list of substitutions to apply.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>