Skip to content

Commit 9763cc9

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 498da62 commit 9763cc9

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@ Bug Fixes to C++ Support
813813
- Clang now allows ``@$``` in raw string literals. Fixes (#GH93130).
814814
- Fix an assertion failure when checking invalid ``this`` usage in the wrong context. (Fixes #GH91536).
815815
- Clang no longer models dependent NTTP arguments as ``TemplateParamObjectDecl`` s. Fixes (#GH84052).
816+
- Fix incorrect merging of modules which contain using declarations which shadow
817+
other declarations. This could manifest as ODR checker false positives.
818+
Fixes (`#80252 <https://github.com/llvm/llvm-project/issues/80252>`_)
816819

817820
Bug Fixes to AST Handling
818821
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/AST/ASTContext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6794,7 +6794,7 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const {
67946794
// Using shadow declarations with the same target match.
67956795
if (const auto *USX = dyn_cast<UsingShadowDecl>(X)) {
67966796
const auto *USY = cast<UsingShadowDecl>(Y);
6797-
return USX->getTargetDecl() == USY->getTargetDecl();
6797+
return declaresSameEntity(USX->getTargetDecl(), USY->getTargetDecl());
67986798
}
67996799

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

clang/test/Modules/cxx20-decls.cppm

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ using xxx = baz::foo;
2828
// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ ]*]]
2929
// CHECK: TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 0x[[ALIAS_ADDR:[^ ]*]]
3030
// FIXME: UsingShadowDecl should have been merged
31-
// CHECK: UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in A.<global> hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
31+
// CHECK: UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} imported in A.<global> {{.*}} 'foo'
3232

3333
// CHECK-LABEL: Dumping baz:
3434
// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
35-
// CHECK: UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'
35+
// CHECK: UsingShadowDecl 0x[[SHADOW_ADDR]] {{.*}} 'foo'

0 commit comments

Comments
 (0)