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

    <tr>
        <th>Summary</th>
        <td>
            [Modules] Incorrect ODR checks caused by `preferred_name` attribute.
        </td>
    </tr>

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

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

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

<pre>
    I met an incorrect ODR checks caused by `preferred_name `. Here is a reduced example.

```
// string_view.h
template<class _CharT>
class basic_string_view;

typedef basic_string_view<char> string_view;

template<class _CharT>
class
__attribute__((__preferred_name__(string_view)))
basic_string_view {
public:
    basic_string_view() 
    {
    }
};

inline basic_string_view<char> foo()
{
  return basic_string_view<char>();
}
// A.cppm
module;
#include "string_view.h"
export module A;

// Use.cppm
module;
#include "string_view.h"
export module Use;
import A;
```

The input command line is:
```
clang++ -std=c++20 --precompile A.cppm -o A.pcm
clang++ -std=c++20 --precompile Use.cppm -fprebuilt-module-path=.  -fsyntax-only
```

The output would be the incorrect ODR warning:
```
string_view.h:11:5: error: 'basic_string_view<char>::basic_string_view' from module 'A.<global>' is not present in definition of 'string_view' provided earlier
```

I've been fighting with the problem for several days. My current process is that when the ASTReader reads the `preferred_name` attribute, it would read the `string_view` type and find an existing one. However, the current behavior would create another RecordType for `string_view` despite there is already one. So here is the problem.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVd-P4jYQ_mvCy4goOASWBx5YuFP34VRpbyv1LXLiCXHPsVPbgeW_7zgJLCwt7UldeYM99vfND8-MCyNO6xdo0APXIHVprMXSw6-7VyhrLH84KHnnUEBxgmiRtBYrpCMi17zBIInhF7QI0gEHknclncV33rQK4yjZRclm_C6ScQxL9pUGOG-l3ucHice4HnY8EpZ7jNJtqbhzkG9rbt-i9MuwPwgL7mSZX8Gj9PlanT-1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