<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/91418>91418</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang][PCH] Initialization order issue after change to lazy initializer loading
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wolfy1961
</td>
</tr>
</table>
<pre>
After commit [bc73ef0031](https://github.com/llvm/llvm-project/commit/bc73ef0031b50f7443615fef614fb4ecaaa4bd11) we see an incorrect initialization order with the attached code. This occurs with PCH use only.
With a vanilla native clang with the above commit on Ubuntu 22.04:
clang -fmath-errno -o t.pch -x c++-header t.h
clang -fmath-errno -S t.cpp -include-pch t.pch
clang -o t t.s -lm
./t
we get the expected
p:0.225000
a:7.589466
b:1.633843
A:7.589466 7.589466 7.589466 7.589466
B:1.633843 1.633843 1.633843 1.633843
But with
clang -fno-math-errno -o t.pch -x c++-header t.h
clang -fno-math-errno -S t.cpp -include-pch t.pch
clang -o t t.s -lm
./t
we get
p:0.225000
a:7.589466
b:1.633843
A:0.000000 0.000000 0.000000 0.000000
B:0.000000 0.000000 0.000000 0.000000
Looking at the code the vectors 'A' and 'B' are initialized before 'a' and 'b' in the failing example.
[init.zip](https://github.com/llvm/llvm-project/files/15242786/init.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVE2v5SYM_TXcjRUEBPKxyOJmrq6mUhcjtVXXhDgJLRciQt7Xr6-SaPrSap7UjiYLcmTsg33A1stiR4_YENUSdbvoNU0hNs_BDa-8LvilC_1rcx0SRjDh8bAJiGo7U-Y4MJZzom5EVFNK80LyKxF3Iu6jTdPaURMeRNyde_r6y-YY_kCTiLgfVETc35k6xYZSyrzgasCh4HLoJBqttex6zomo4RlhQQTtwXoTYkSTwHqbrHb2TScbPITYY4RnmyZIE4JOSZsJezChRwq_TnaBYMwal8Pny6fPsC4IwbtXStiNsOux_r7tanjS3jqnwetknxCM0348sXdhMx6qBA-_datPKwhBmdzEOPEdkdnw0GnKMEYfIAuQ6GwmyF7AENES0WYT6i3_RKePw36BRM08Q2a9cWuP2caxM_0jJkCCRBfI3OOwUyLu6ZzTM8KIaa8EX2Y0Cfvz9kzyK6NCKMbYYdEkv5ZUVbUsisPSkfzKaZHnlcwPy_XkAx-Dw7k9hcPH4JxVu6b9Ar4lrg_Zd-r7r8gfLfGPkZVRtn_wMXiX9T87H-vPIfxp_Qj6eA9bu-zgCU0KcQEiyisRJWjfb7jdccT39sMeOhxCxG1bn1y7DVu_sw3auu0UfNGP2eHXjlPtRkPf7Pyd02SwDhci7lwJKcqqIOL-N6Ooz3Ve-ibv67zWF2x4yRXPhSzyy9SIHLFArgZTcFZoVrJSGyYNmgo7VVUX2wgmJFOsYlxyltO6FkoOijNkQtSVJpLhQ1tHt-RoiOPFLsuKTc0lry5Od-iWfcoKsb8fIsQ2cGOzF9Ot40Ikc3ZJyztDssnto_mIUDei2i-fPhN1g5--Nfj2E0Ef03rSfkRIAZx-ez3dVAQXdG_9eFmja_632PsZm9p7YX8FAAD__7wH09Q">