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

    <tr>
        <th>Summary</th>
        <td>
            [Win64] EHcont just doesn't seem work with SEH
        </td>
    </tr>

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

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

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

<pre>
    Reproducer:

```
#include <cstdio>

[[gnu::noinline]] void exception() {
    *(char*)1 = 0;
}

__asm__(R"(
.text
.balign 16
.globl test_seh
.def test_seh; .scl 2; .type 32; .endef
.seh_proc test_seh
test_seh:
 .seh_handler __C_specific_handler, @except
  .seh_handlerdata
  .long 1
  .long (seh_begin)@IMGREL
  .long (seh_end)@IMGREL
  .long 1
 .long (seh_except)@IMGREL
  .text
seh_begin:
  nop
  int3
 nop
seh_end:
seh_except:
  ret
.seh_endproc

.section .gehcont$y,"dr"
.symidx seh_except
)");

extern "C" void test_seh();

int main() {
    test_seh();
    printf("Test from assembly worked!\n");
    __try {
        exception();
    } __except(1) {
    }
    printf("Test from C worked!\n");
 return 0;
}
```

Output (link.exe is used for linking due to [lld bug with EHcont](https://github.com/llvm/llvm-project/issues/64570)):

```
> clang-cl --version
clang version 16.0.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

> clang-cl /guard:ehcont -fuse-ld=link test.cpp /link /guard:cf,ehcont

>.\test.exe
Test from assembly worked!

> echo %ERRORLEVEL%
-1073740791
```

I'll investigate a bit more to find out where the issue could be, as this functionality is supposedly tested by https://github.com/llvm/llvm-project/blob/345acac85d382998e5721073cc077e47e799311f/llvm/test/CodeGen/X86/ehcontguard.ll
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVt2O27gOfhrlhohhy5Z_LnLRyU9bYIoezCl6zl0gW4ytVpYMSZ5J9ukX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