Skip to content

Commit db966f6

Browse files
committed
[clang] fix merging of UsingShadowDecl
Previously, when deciding if two UsingShadowDecls where mergeable, we would incorrectly only look for both pointing to the exact redecla ration, whereas the correct thing is to look for declarations to the same entity. This problem has existed as far back as 2013, introduced in commit fd8634a. This problem could manifest itself as ODR check false positives when importing modules. Fixes: #80252
1 parent 7bd920a commit db966f6

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ Bug Fixes to C++ Support
188188
and (`#79745 <https://github.com/llvm/llvm-project/issues/79745>`_)
189189
- Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated.
190190
Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_)
191+
- Fix incorrect merging of modules which contain using declarations which shadow
192+
other declarations. This could manifest as ODR checker false positives.
193+
Fixes (`#80252 <https://github.com/llvm/llvm-project/issues/80252>`_)
191194

192195
Bug Fixes to AST Handling
193196
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ASTContext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6733,7 +6733,7 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const {
67336733
// Using shadow declarations with the same target match.
67346734
if (const auto *USX = dyn_cast<UsingShadowDecl>(X)) {
67356735
const auto *USY = cast<UsingShadowDecl>(Y);
6736-
return USX->getTargetDecl() == USY->getTargetDecl();
6736+
return declaresSameEntity(USX->getTargetDecl(), USY->getTargetDecl());
67376737
}
67386738

67396739
// Using declarations with the same qualifier match. (We already know that

clang/test/Modules/GH80252.cppm

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ import A;
4040
import B;
4141
// Since modules are loaded lazily, force loading by performing a lookup.
4242
using xxx = bar;
43-
// FIXME: This is a false positive ODR violation.
44-
// expected-error@bar.h:2 {{'bar' has different definitions in different modules; first difference is defined here found constructor with 1st parameter of type 'baz::foo' (aka 'char')}}
45-
// expected-note@bar.h:2 {{but in 'B.<global>' found constructor with 1st parameter of type 'baz::foo' (aka 'char')}}
43+
// expected-no-diagnostics

clang/test/Modules/cxx20-decls.cppm

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ using xxx = baz::foo;
3131
// CHECK-NEXT: | `-BuiltinType {{.*}} 'char'
3232
// CHECK-NEXT: |-UsingDecl {{.*}} baz::foo
3333
// CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz'
34-
// FIXME: UsingShadowDecl should have been merged
35-
// CHECK-NOT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} {{.*}} imported in A.<global> {{.*}} 'foo'
36-
// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} {{.*}} imported in A.<global> {{.*}} 'foo'
34+
// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} imported in A.<global> {{.*}} 'foo'
3735

3836
// CHECK-LABEL: Dumping baz:
3937
// CHECK-NEXT: NamespaceDecl {{.*}} baz
4038
// CHECK-NEXT: |-TypeAliasDecl {{.*}} foo 'char'
4139
// CHECK-NEXT: | `-BuiltinType {{.*}} 'char'
4240
// CHECK-NEXT: |-UsingDecl {{.*}} baz::foo
4341
// CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz'
44-
// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} 'foo'
42+
// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR]] {{.*}} 'foo'

0 commit comments

Comments
 (0)