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

    <tr>
        <th>Summary</th>
        <td>
            Incorrect section assigned to static-initialized-variable
        </td>
    </tr>

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

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

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

<pre>
    Hi everyone.

Kindly find attached the files for reference, in the below steps :

- reproducer.c is the file which is being compiled.

- The variable under question is “testVar”, which has been initialized to 1, and thus ought to go in the .data section, irrespective.

- Upon compiling with -O0, testVar gets assigned to .data section, as expected.
-- ./do.sh -O0
-- Contents can be seen in dump_-O0

- Upon compiling with -O2, testVar gets assigned to .bss section, which is wrong.
-- ./do.sh -O2
-- Contents can be seen in dump_-O2

Have tested on LLVM/Clang 15, 17, 18, 19 - behaviour is identical.
Plus, the issue is not powerpc-specific; occurs even for x86 targets.

Long standing bug?

Thanks and Regards,
Ajay

[do.sh.txt](https://github.com/user-attachments/files/19361007/do.sh.txt)
[dump_-O0.txt](https://github.com/user-attachments/files/19361009/dump_-O0.txt)
[dump_-O2.txt](https://github.com/user-attachments/files/19361008/dump_-O2.txt)
[reproducer.c.txt](https://github.com/user-attachments/files/19361016/reproducer.c.txt)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVEmPpDYU_jXm8gQyj4KCA4degiZKR4miyVwjY16BO5RNbFPVlV8f2VT19GSiVg59McLLt7xNOKdGTdSy8p6Vj4lY_WRsK57FZRR2rHdJb4ZL-0kBnchejKaM8TvG735SepgvcFB6AOG9kBMN4CeCg5rJwcFYsHQgS1oSwwdQOp72NJszOE-LA1bcbVgpWFqsGVZJNpOg3CsQnCclp7DTk9IjSHNc1ExDdnv4eSI4CatEPxOseiALf63kvDI6vGI_IKs5ax48Of9F2Nv_Y5C0YU8igJMGpZVXYlZ_ByMG8nBF6GBqdWDWcfJhezQ3K9kgvABHMpBFi9aSW8L_iV4F_r4YfZUdDJyVnyD9hYf7V00wkndwTUSk_g5ZOKCXgLw5T1PIGHaDydwGFrcejPakvQMpNPQEbjMFw3pc_thuvaMI31fUO_dW0Gtaztbo8T804f_ShJumT-JEkZsGMBqenr78zLB7mIUeIS8DX76Pax3XBlLoaRInZVYbRKiBtFdSzEHIr_PqopeJQDm3hhW08bCYM9lFpiFF6qAkK-7BSLlaF2pbx5J9qSvwwgb_1ww-GT2C80IPIVj9OrKi204-T0L_6WKJ_EajsEOgZfzu7llcthusvI_xyPyLZ-Ujw3ryfnGh7rFj2I3KT2ufSXNk2K2ObLp10jGEjGEXW4lhlzdFlXO-v8U34mFzZbim94NImkDyFvJfPPhBPPVXHvyG5-0o-BiuvGLYfQeLTTK0xdAUjUiozfc73JVVWfJkaqv9rq-bnOdY8rzqUfRNKRqxP_Cqof7QJ6pFjiUvkPP9DgueVVQfEKnOi35fCUS243QUas7m-XTMjB2TWIptXmBeVskseppdnLmIms5boTLEMIJtGx6l_To6tuOzct59hfHKz9T-qKWxlqS_9eQ3zeq88Eqmb-ZZehuRyWrn9p1YBp7rJ12seSbpGXZRXYznJv_U4j8BAAD__2yxAcY">