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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] C++ Modules:  Setting section attribute on variable in module causes miscompilation
        </td>
    </tr>

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

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

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

<pre>
    Setting the output section of a variable by attribute in a module interface causes miscompilation. 
Code works fine if not using c++ modules or if removing section attribute.

**Example**
test.ccm:
```
export module test;

int foo  __attribute__((section(".data.foo"))) = 2;

export int get_foo()
{
        return foo;
}

export void set_foo(int val)
{
        foo = val;
}

```
main.cc:
```
import test;

int main()
{
        set_foo(5);
        return get_foo();
}
```

Compile and run:
clang++ -std=c++23 -O1 -c test.ccm -fmodule-output=test.pcm
clang++ -std=c++23 -O1 -c main.cc -fmodule-file=test=test.pcm
clang++ test.o main.o -o test
./test
echo $?

**Expected result:**
5

**Actual result:**
2

**Clang version**
clang++ --version
clang version 19.1.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE-PuzYQ_TTOZQQyJhA4cGA3peqh6qG9R8YMxK2xkf-k-X37ykB2k-5WqmQpwLx5b2Y8edw5OWnEhhRvpDgfePBXY5ufg-XXQ2-GH83v6L3UE_grggl-CR4cCi-NBjMChxu3kvcKof8B3Hsr--ARpAYOsxmCis8e7cgFguDBoYNZOmHmRSoeaVIgtH03A8Lfxv7lYJQaQY6gjYfgorQg7I2wt53PgbExbnE2txh-lPOhnhLaxsPi-enO50Xh9kJo69H5VIiZ5CumpPuhLd4XY_2j6ogj-dtGJbWH0RiAy-VD5XIhrCKs2uXXF5YO3PN0NIYwRli9HSD5GdgH2a4TOSf0lxVcRSRtyWnD1BZ9sDpq7mmn80vyzcgB3Ed25Lpx9S-SWHGUjpFXlue2Zy51KsTXech5lfoyiJjwteLPYooYyV8beW30uZgnwXUP4l4gcD2ADXorSiiup30HEucHkp_3lWA5JL9lkAh4XCsk43aBybasJD-voUXM_5Npn8cn0SgV7jT_zbZ-NluygcRsY6NtSli3P6K4GiDsSPLudUEXFB4HsOiC8rHlx64Wz7hW-MDVNyj2jHqPNcENrVt3coe89J08ovv3BxqyOs3SE6HtH9xOGDXgXpWX8pgsIlFSh3sy6RDjV4t8iP8UVBG1GCfvhLa_aOe5UjicpY3fCeuCs4R1vYxqh6HJhzqv-QGb7FRQWtI6yw_XRoi-HqvxRDNaliPNBloNeYmMlkIU9ZEdZMMoK2iZlbSiWZGn2Of1aex7Xlen6lhxcqQ4c6lSpW5zaux0kM4FbLLjMc_YQfEelVtNjrF9GCz6nW1iQtKHyZEjVdJ590nhpVerM65DJcUZ3vcZ_ro5UewRHgb5xYbA6E93lPphLN-a4CFY1Vy9X9x6sx1h3ST9NfSpMDNhXaxp_0kWa_5E4Qnr1h4dYd3e5q1h_wQAAP__N3nHMA">