<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118644>118644</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crash on Windows when running pass plugin
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
FenixH
</td>
</tr>
</table>
<pre>
I am attempting to create an example pass plugin on Windows. I have built LLVM from source through the build instructions on https://llvm.org/docs/GettingStartedVS.html using VS 2022.
Notably, I made a tiny modification to `PassPlugin.h` (`__declspec(dllimport)`) as `llvmGetPassPluginInfo` else was not exported:
```
extern "C" __declspec(dllimport) ::llvm::PassPluginLibraryInfo
LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo();
```
The pass works as intended if tested using opt.exe (` "..\build\MinSizeRel\bin\opt.exe" -load-pass-plugin "C:\Projects\tutorial-llvm-pass\HelloWorld\build\MinSizeRel\Hello.dll" -passes "hello-world" test_hello.ll`).
clang however crash (`"..\build\MinSizeRel\bin\clang.exe" -fpass-plugin="C:\Projects\tutorial-llvm-pass\HelloWorld\build\MinSizeRel\Hello.dll" -Xclang -disable-O0-optnone test_hello.c`):
```
Stack dump:
0. Program arguments: C:\\Projects\\build\\MinSizeRel\\bin\\clang.exe -cc1 -triple x86_64-pc-windows-msvc19.37.32822 -emit-obj -mincremental-linker-compatible -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test_hello.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -fdebug-compilation-dir=c:\\Projects\\tutorial-llvm-pass -v -fcoverage-compilation-dir=c:\\Projects\\tutorial-llvm-pass -resource-dir C:\\Projects\\build\\MinSizeRel\\lib\\clang\\20 -internal-isystem C:\\Projects\\build\\MinSizeRel\\lib\\clang\\20\\include -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.37.32822\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.37.32822\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\[test_hello-bce248.zip](https://github.com/user-attachments/files/18009652/test_hello-bce248.zip)
\10.0.22621.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt" -ferror-limit 19 -fmessage-length=478 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.37.32822 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcolor-diagnostics -fpass-plugin=C:\\Projects\\tutorial-llvm-pass\\HelloWorld\\build\\MinSizeRel\\Hello.dll -faddrsig -o C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\test_hello-ddf9f5.o -x c test_hello.c
1. <eof> parser at end of file
2. Optimizer
3. Running pass "function(`anonymous-namespace'::HelloWorld)" on module "test_hello.c"
Exception Code: 0xC0000005
#0 0x00007ffafa947519 llvmGetPassPluginInfo (C:\Projects\tutorial-llvm-pass\HelloWorld\build\MinSizeRel\Hello.dll+0x7519)
#1 0x00007ffafa9474f1 llvmGetPassPluginInfo (C:\Projects\tutorial-llvm-pass\HelloWorld\build\MinSizeRel\Hello.dll+0x74f1)
#2 0x00007ffafa948737 llvmGetPassPluginInfo (C:\Projects\tutorial-llvm-pass\HelloWorld\build\MinSizeRel\Hello.dll+0x8737)
#3 0x00007ffafa9433ee (C:\Projects\tutorial-llvm-pass\HelloWorld\build\MinSizeRel\Hello.dll+0x33ee)
#4 0x00007ff614d14b81 (C:\Projects\build\MinSizeRel\bin\clang.exe+0x7d4b81)
#5 0x00007ff61521855f (C:\Projects\build\MinSizeRel\bin\clang.exe+0xcd855f)
#6 0x00007ff6152159c7 (C:\Projects\build\MinSizeRel\bin\clang.exe+0xcd59c7)
#7 0x00007ff61521601f (C:\Projects\build\MinSizeRel\bin\clang.exe+0xcd601f)
#8 0x00007ff61586877b (C:\Projects\build\MinSizeRel\bin\clang.exe+0x132877b)
#9 0x00007ff616457f5b (C:\Projects\build\MinSizeRel\bin\clang.exe+0x1f17f5b)
#10 0x00007ff615a43e3d (C:\Projects\build\MinSizeRel\bin\clang.exe+0x1503e3d)
#11 0x00007ff615867621 (C:\Projects\build\MinSizeRel\bin\clang.exe+0x1327621)
#12 0x00007ff615a43cbb (C:\Projects\build\MinSizeRel\bin\clang.exe+0x1503cbb)
#13 0x00007ff615a31f64 (C:\Projects\build\MinSizeRel\bin\clang.exe+0x14f1f64)
#14 0x00007ff615ac283d (C:\Projects\build\MinSizeRel\bin\clang.exe+0x158283d)
#15 0x00007ff6145a1296 (C:\Projects\build\MinSizeRel\bin\clang.exe+0x61296)
#16 0x00007ff61459b87f (C:\Projects\build\MinSizeRel\bin\clang.exe+0x5b87f)
#17 0x00007ff61459c67e (C:\Projects\build\MinSizeRel\bin\clang.exe+0x5c67e)
#18 0x00007ff6145a9d9f (C:\Projects\build\MinSizeRel\bin\clang.exe+0x69d9f)
#19 0x00007ff61722cc18 (C:\Projects\build\MinSizeRel\bin\clang.exe+0x2cecc18)
#20 0x00007ffb32407374 (C:\Windows\System32\KERNEL32.DLL+0x17374)
#21 0x00007ffb32e1cc91 (C:\Windows\SYSTEM32\ntdll.dll+0x4cc91)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 20.0.0git (https://github.com/llvm/llvm-project.git 83cbb170449b17aa3e1ada514c94d9e9b4f0fca6)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Projects\build\MinSizeRel\bin
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: C:\Users\ADMINI~1\AppData\Local\Temp\test_hello-bce248.c
clang: note: diagnostic msg: C:\Users\ADMINI~1\AppData\Local\Temp\test_hello-bce248.sh
clang: note: diagnostic msg:
********************
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWVFz27iu_jXMC4YeiZIs-SEPrpO0mU3bTJNt733q0CRkc0uRGpJynH24v_0OJSWys-menuPd7slkxhZNfh8AAiBAce_VxiCek-INKS7OeBe21p1foVH7d2drKx_Pr4E3wEPApg3KbCBYEA55QOAGcM-bViO03HtodbdRBqyBL8pI--BncA1bvkNYd0oHuLn5_B5qZxvwtnMCIWyd7TZbCNthigRlfHCdCMoaH4G2IbSeZEvCrgi70nrXzKzbEHYlrfCEXb3FEIW6C9wFlJ_vZtvQaOh8FPTzHbCEsRmQZEmS5Qcb-Fo_EraCa2i4ROAQlHmExkpVK8EjadSOzJNb7v1tr81sS-YJEFaRefL1q0ShfYuCsEpqrZrWukDYgswTwhbAfVwbhXyLYYK4NrWNIKg9wgP3YGwA3Me1KKNuyTICDP_JEvcBnQHC2IowBt8lhbg0W0a64dvEeKPWjrvHnjhZAkBv-q_L-_tP129-vb_8-uVy-Qu8LiirokLZmxdSkWR5vx33-cG6bz5qq0xAI1GCqiGgDyhH09s2zHCPo92iLrMZKVb9HpNi9V6ZO_U7fkIdB5UhxWpcETWm2nJJIxMdPaq3RbYkxerW2d9QBE-KVeiCdYprGvXop5Ni9Q61tl-s62lepetnzKTWPVVchj4SbOM4feiXMtar87Ufm2k97O-TIwnNzQa29gF36EA47rejoj-gZ7_4WdP6QEuSXfx9ev7PIDSVyvO1RvoxobYNxho81FQMio4-eewAd4GLbyC7ph1-TmZw6-zGxeTgNl2DJsRAhVGBYx0OhHwp57NlDo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