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

    <tr>
        <th>Summary</th>
        <td>
            [C++20] [Modules] Incorrect modules owner ship for implicitly generated declaration for builtin expressions
        </td>
    </tr>

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

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

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

<pre>
    Live example: https://godbolt.org/z/P7Gexcc1f

Minimal example:

```
export module mod;
export auto a = __builtin_expect(true, true);
```

in the dumpped text, we can see:

```
FunctionDecl 0xc0d1d30 <col:17> col:17 **in mod** hidden implicit used __builtin_expect 'long (long, long) noexcept' extern
 |-ParmVarDecl 0xc0d1e38 <<invalid sloc>> <invalid sloc> in mod hidden 'long'
    |-ParmVarDecl 0xc0d1ea8 <<invalid sloc>> <invalid sloc> in mod hidden 'long'
    |-BuiltinAttr 0xc0d1dd8 <<invalid sloc>> Implicit 528
    |-NoThrowAttr 0xc0d1f20 <col:17> Implicit
    `-ConstAttr 0xc0d1f48 <col:17> Implicit
```

the message shows the implicitly generated declaration `__builtin_expect` are considered to be attached to the module 'mod'.  This shouldn't be correct. Another more straight forward example is:

```
export module mod;
export extern "C++" auto a = __builtin_expect(true, true);
```

(https://godbolt.org/z/farvae3Pn)

```
FunctionDecl 0xc4b6da0 <col:30> col:30 in mod hidden implicit used __builtin_expect 'long (long, long) noexcept' extern
    |-ParmVarDecl 0xc4b6ea8 <<invalid sloc>> <invalid sloc> in mod hidden 'long'
    |-ParmVarDecl 0xc4b6f18 <<invalid sloc>> <invalid sloc> in mod hidden 'long'
    |-BuiltinAttr 0xc4b6e48 <<invalid sloc>> Implicit 528
    |-NoThrowAttr 0xc4b6f90 <col:30> Implicit
    `-ConstAttr 0xc4b6fb8 <col:30> Implicit
```

We've put the expression in language linkage, but it is still being put into the named module. This is not correct absolutely.

The expected behavior is to not assign a module for it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VsFu4zYQ_Rr6MohBkbIlH3xw7HWxQLfIIWh7CyhyLLGlSJWkHKdfX1CSG2-cJgt0s4AgSqLezOPwvQFFCLq2iGuyuCWMbZte2L_07_2KMEYWu5noY-P8-vn7rHLqaf2zPiLgSbSdQcI30MTYBcI3hO0J29dOVc7EufM1Yfu_CdvfFT_hScrsQOiO0M14_6KtboW5iHM5S5Z0uoZXPHXOR2id6g2mgfDbr2ZEHx0IIHwHDw9Vr03U9gFPHcpIWBl9j4RtYRxX_4JfZBnv2kJsEFTfdh0qiHiKCfuIIIWFgO9Q3fdWRu3sDqUBepJUZYpTIHwrnSF8kxWEf4LzMxC2ISzlTIsanqHRSqEF3XZGSx2hD6iuVgWEFcbZGggr05gojuMKrMOTxC4SVgCeIno7UgNSbG_uhG9_Ff6CHvIy0SN8q-1RGK0gGCcJ_5SIXn-FkeyZ5sSDsGJKAvBfecRH5Lkdy7KJ0Z_Lrd7I8_lc1QUrvw70i7tvvHu8CHRgV_t2hl9Al_Rm62yIl8C8fBv4qvCS6loMQdQIoXGPYdDhWQbmCWq06EVEBQqlEV4knSUCV5JfUhAeQTobtEKfZOygQhAxCtmMr0O60VCEFYP8ijnAfaNDSt8bZQkrYoJJ5z3KOIeNdbFBD63zCCF6oesmwsH5R-HV2cqgw_908yhaSC2JsNvhYt_T4oSV7_Wsg_BHgfzOpmDf7va8WipxoRpOn93O6QtJf4DDXzdfXi0_xnzXeQ7ZDzB5Wk_-PUyeCK-utusbTJ6AVfk28FXp_YaEFUeEro-DA_HUeQwhGVlbMMLWffK_0fZPUQ-KrvoIOkJyZdTGQIXa1gNe28nGVrSoJj_NRwfrANbFs3NBVMGZPqJ5ml-yuR8ZoExNpcJGHLXzCRvdAB8PCCDOXj2k2TifqTVXK74SM1xnBWNlXhRlPmvWGeYll1QyRfmhXPKC50yWitGMyYXIFzO9ZpTltKQLWuarPJ9Lni2zjCtKS8nyKic5xVZoMzfm2CY_znQIPa4zmq34amZEhSZM5xWZykX4ZiQXpkOLXyfoTdXXgeTU6BDDc7CooxmOO1NjYZQsdkAWt1-mGIsdfLbnqk2BwT1a9BAa3Y0VeK8lp58mM19scJj13qxfNB4dm76aS9cStk8sp-Gm8-6PobPth_UHwvZTCY5r9k8AAAD__2J-_x0">