<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80252>80252</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] incorrect merging of UsingShadowDecl
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:modules
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
mizvekov
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mizvekov
</td>
</tr>
</table>
<pre>
When merging imported modules, equivalent UsingShadowDecls from the TU and from the module would not be merged, resulting in them becoming different entities, instead of redeclarations.
A simple reproducer would be:
`foo.h`
```
namespace baz {
using foo = char;
using baz::foo;
}
```
`A.cppm`
```
module;
#include "foo.h"
export module A;
```
`B.cpp`
```
#include "foo.h"
import A;
// Since modules are loaded lazily, force loading by performing a lookup.
using xxx = baz::foo;
```
Building this with:
`-cc1 -std=c++20 -emit-module-interface -o A.pcm A.cppm`
`-cc1 -std=c++20 -fmodule-file=A=A.pcm -fsyntax-only -ast-dump-all -ast-dump-filter baz C.cpp`
This would result in the following AST:
```
NamespaceDecl ... baz
|-...
`-UsingShadowDecl 0x2563bdbe448 ... imported in A.<global> hidden implicit TypeAlias ... 'foo'
...
NamespaceDecl ... baz
|-...
`-UsingShadowDecl 0x2563bdbe1a0 ... implicit TypeAlias ... 'foo'
```
The first UsingShadowDecl should have been a redeclaration of the second one.
You would expect:
```
NamespaceDecl ... baz
|- ....
`-UsingShadowDecl 0x1b63f707b58 prev 0x1b63f7078b0 ... imported in A.<global> hidden implicit TypeAlias ... 'foo'
...
NamespaceDecl ... baz
|- ....
`-UsingShadowDecl 0x1b63f7078b0 ... implicit TypeAlias ... 'foo'
````
This was originally reduced from this example that manifested itself as an ODR violation in the global module fragment:
`foo.h`
```
namespace baz {
using foo = char;
using baz::foo;
}
```
`bar.h`
```
class bar {
bar(baz::foo);
};
```
`A.cppm`
```
module;
#include "foo.h"
export module A;
```
`B.cppm`
```
module;
#include "foo.h"
#include "bar.h"
export module B;
```
`C.cpp`
```
#include "foo.h"
import A;
#include "bar.h"
import B;
// Since modules are loaded lazily, force loading them by performing a lookup.
using xxx = bar;
```
And this compilation would result in an ODR false positive, where the definitions for the bar constructor don't match due to different parameters. This failure stopped happening when we merged the patch to disable the GMF ODR check.
This had been further reduced from a similar example with pure inclusion of libc++ headers, on MSVC platform. `s/foo.h/stddef.h` `s/bar.h/locale`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV0tv4zYQ_jX0ZSBBphzZOfhgx01P2wJNtkWPFDm02KVIlaQcO7--ICW_Nsm-GmCBRIZIceab-eZF5r3aGsQluVkTSlv1vMNPdkcoJTebCetDY93yuDqprTgs_2rQQItuq8wWVNtZF1BAa0Wv0RN6B_hvr3ZMownw0SuzfWiYsE8b5NqDdLaF0CA8fgRmxPl9OA9PttcCjA1QY1KCIop06HsdkkITP2-hRm7buCCUlOiiMjRBBTVgUMYHZAKsBIcCuWaOBWWNz0mxIcVqeK7Aq7bTCA47Z0XP0Y0IaiTl6vJTUhXS2rwhVXFaGP_Sq2Et-o5xhJo9A5mvh2WAProApLVAyg3whjlSHjeHvZo9R2XlSlp72iPzzat6TournHdd-xacwZ1nabRUhuteIBBKB0MoHfZwHyk8ErA6n3lD8ToqfkvvlxQNsXKpgd4Teg8PyvBjAHhgDkFbJlCAZs9KHyKd0jo-LCeHHaBDJ61LAcBAW_up70ZmB5_u9_vk79d9-5pl617pJD00ysOTCs05Aqoi43wKmQ-ClBtO6JrQNS0gw1aFbECeKRPQyRgBmYVV3vEWXnL0hhw5ypAqkrZZxf8kIZP-YALbZ9boA2TMh0z0bZcxrS_epNIBXYq8u2t20vMxWZTiekikMYtAWq3tUzR69fB4ae6le347RnbMYMjzPDl1DNK7LM_zs3Wf5TsUe3pTlbWocTZbpLOngqEMrHJS3m21rZkm5S_QKCHQxC-04irA46HDlVbMp4OEziOHdH5p2Vn5O0KdsuII9VuAvBZMj9G5yvkXFRB8k3ho2A6hRjTArgtU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