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

    <tr>
        <th>Summary</th>
        <td>
            [Windows][Intel x64] Jump table entries seems not valid while targeting MSVC 2022
        </td>
    </tr>

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

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

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

<pre>
    In your project we use LLVM-powered part which compiled with embedded LLVM to an .obj file then gets linked into our main binary. Other parts are in C or C++ and compiled with clang-cl.exe supplied by MSVC 2022 as a ClangCl toolset (at the moment the latest is 17.0.3).
After updating our embedded LLVM from version 16 to 18.1.7 we can see our application crashing. 

Investigations indicate that the crash happened after calculating a jump target from jump table - the resulting jump target value is not correct.
In version 16 a jump table entry was 32-bit, and the result jump target has been calculated by sign-extending jump table entry value, like this:
```
        movabs  r10, offset .LJTI536_0
        movsxd  r9, dword ptr [r10 + 4*r9]
        add     r9, r10
        jmp     r9
```
In version 18 jump table entries are now 64-bit, so the accessing code now doesn't sign-extend entry value
```
        movabs  r10, offset .LJTI536_0
        add     r10, qword ptr [r10 + 8*r9]
        jmp     r10
```

I'm not sure why, but I can see that jump table entry values are still 32-bit. Thus, if values are negative and they don't get sign-extended, then the result jump target becomes invalid. See the screenshot attached.

Is this a bug in LLVM 18? Or some incompatibility issue, for example with MS linker or clang-cl version 17.0.3 which we use for C parts?
Obviously, disabling jump tables fixes the issue for us, but we want them to be enabled.
LMK if you need more info or any other help for this issue.

<img width="942" alt="jump tables" src="https://github.com/llvm/llvm-project/assets/1537180/6e8ffa8f-b5c3-4e79-8bbc-b2663d268592">

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVkFv2zgT_TX0ZWBBpmRZOvjQOJ-B9EvQQ4vucUGKI4kpRWpJyor__YKkndht97BYIEhiYjjz5s2bRzPn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