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

    <tr>
        <th>Summary</th>
        <td>
            False positive in UndefinedBehaviorSanitizer on Apple M1
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    When using homebrew's `clang`,

```
% clang --version
Homebrew clang version 15.0.2
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
```
compiling the code below with a sanitizer
```
clang -fsanitize=undefined foo.c
```

produces a binary that gives the error

```
% ./a.out
foo.c:27:12: runtime error: index -60 out of bounds for type 'int[200]'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior foo.c:27:12 in
```

When compiled without the sanitizer option the code produces the expected result

```
clang foo.c
```
```
% ./a.out; echo $?
123
```

Here's the code (to be placed in `foo.c`)
```
__UINT_LEAST8_TYPE__ c = '\xc4';
int table[200] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 123, 0, 0, 0};

int main(int argc, char** argv) {
    return table[+c];
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVt1vmzAQ_2vgxQoCAyF54CFpWnXSOk1rqqlPkYELeHIwsk0-9tfvDJSoVZpp0h6DkDG-T__OvrtMFqf0ZwU1aTWvS1LJHWQKDg5NNHGmfi5YXeLXoXeOv3L8xTDiSv_2vzQmHSeZTPagNJd1T3gc1A3UgUaC2PM92rOsmSrBOOGCMLWbRhPWNAImBVMHXtPAm3qDjXWlgBVkJwsQlruRmh970pdaGyYEFCuuLMmhD7IxOJ53MywIsd_hJ-P1xX3kctdwYXEwFZAcTZEMhDyQAzcVYUSzmhv-G9Rl6R6B7RuXE67auoAtr6EgWym9_DJ43dgoWbQ5aLSC3jF1QheYISXf45r1BpSS6i8x8HBvzJOt6Zd6m-GCJjgE1EKj2trw3Zs2XODo4ZFMpj5BMSK3JJPotEZ_FTGnBhDMhNfGiZfU9514hb-98ueXp6fFj1er4-Vtl0uo2J5L9TzihNQRg0k2kMkHx8gn4ejH7nT2kUEcbSSspxaSMRwEo2vP1Ri1Ec0OuWMDuUFZBboV5gqGfQSvhOoa5OGSQF5JBCxywoeeI6DhlZ09goLuoo1-O3RmJJ450giWo8e8tpewd8hewvlFbZvNy5dv683X-8XzerZZv36_32xITvD82eg58d0xj-wkXPb8GE9iWCZgjGrPmwx0go-98f803ERvojfRm-j_EbWJ88NqshoT2DmN7RjWDjqzU-wjcsuZV0w5FJOz7SjKPSbN95lNgWlVPSZAhy5zW9dG3WjnfZJ1IQ2m03gaxVFC3SINi3k4Z67hRkD6wISGrhkxWKptwv68GhIsUQvb3pCnwG2VSCtjGo0lEGsIviWWtjbzsNSdOxX7mWA1-4UVDH-51i1onMSzMIzdKt1uo5kf0zykdBrPIogSn0Z-mLMsL-ItC1zBsIPRabdRWmMn1qnAOe7Z5Sn1KQ38IPSTIImpB9QPwzkFFE6iuR85kQ8IsfCsH55UpavSzqWsLTUSBddGn4lMa17WAJ051M9aLNYqZVCd9kxxt7Oddr7_ATVimX4">