Skip to content

Commit b44f1b2

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: #ISSUE_TO_BE_CREATED
1 parent 23a0d73 commit b44f1b2

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
181181
and (`#79745 <https://github.com/llvm/llvm-project/issues/79745>`_)
182182
- Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated.
183183
Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_)
184+
- Fix incorrect merging of modules which contain using declarations which shadow
185+
other declarations. This could manifest as ODR checker false positives.
186+
Fixes (`#TODO <https://github.com/llvm/llvm-project/issues/TODO>`_)
184187

185188
Bug Fixes to AST Handling
186189
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ASTContext.cpp

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

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

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 0x{{[^ ]*}} 'char'
3232
// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A.<global> hidden baz::foo
3333
// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
34-
// FIXME: UsingShadowDecl should have been merged
35-
// CHECK-NOT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in A.<global> hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
36-
// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in A.<global> hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
34+
// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A.<global> hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
3735

3836
// CHECK-LABEL: Dumping baz:
3937
// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
4038
// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced foo 'char'
4139
// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
4240
// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
4341
// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
44-
// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'
42+
// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR]] <{{.*}}> col:{{.*}} implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

0 commit comments

Comments
 (0)