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

    <tr>
        <th>Summary</th>
        <td>
            [DirectX] External declaration 'switch.table.*' is unused
        </td>
    </tr>

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

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

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

<pre>
    Currently seeing 6 errors of this on DML shaders

```bash
lldb -- dxv validation/QLinearConvDp4a7x7x2_QLConvI8_u8u8.dat
error: External declaration 'switch.table.CSMain' is unused
```

## Emited Error DeclNotUsedExternal: 
https://github.com/microsoft/DirectXShaderCompiler/blob/adffd31eb02f690d9d1afe86c7fa6f12b4e70aa1/lib/DxilValidation/DxilValidation.cpp#L3798

## Erroring Instruction

```llvm
(lldb) expr GV->dump()
@switch.table.CSMain = private unnamed_addr constant [4 x i32] [i32 1, i32 257, i32 65793, i32 16843009], align 4
```
If we go beyond this breakpoint we eventually hit this assert:
## Assert in:
https://github.com/microsoft/DirectXShaderCompiler/blob/adffd31eb02f690d9d1afe86c7fa6f12b4e70aa1/lib/IR/Globals.cpp#L210
```cpp
void GlobalVariable::setInitializer(Constant *InitVal) {
  if (!InitVal) {
 if (hasInitializer()) {
      // Note, the num operands is used to compute the offset of the operand, so
      // the order here matters.  Clearing the operand then clearing the num
      // operands ensures we have the correct offset to the operand.
      Op<0>().set(nullptr);
 setGlobalVariableNumOperands(0);
    }
  } else {
    /*line 210 -->*/ assert(InitVal->getType() == getType()->getElementType() &&
 "Initializer type must match GlobalVariable type");
    // Note, the num operands is used to compute the offset of the operand, so
    // the order here matters.  We need to set num operands to 1 first so that
    // we get the correct offset to the first operand when we set it.
    if (!hasInitializer())
      setGlobalVariableNumOperands(1);
 Op<0>().set(InitVal);
  }
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/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