diff options
author | Matheus Izvekov <mizvekov@gmail.com> | 2024-02-01 02:26:10 -0300 |
---|---|---|
committer | Matheus Izvekov <mizvekov@gmail.com> | 2024-02-02 02:26:43 -0300 |
commit | db966f66a148ab5b5ba26250cbf0dab6be5a2c29 (patch) | |
tree | b0163dd603235bb7d22dee07012f03b886f7593e | |
parent | 7bd920a14240c85442467706236e0644f320aa5c (diff) |
[clang] fix merging of UsingShadowDeclupstream/users/mizvekov/bug/clang-merge-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
fd8634a09de71.
This problem could manifest itself as ODR check false positives
when importing modules.
Fixes: #80252
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 3 | ||||
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 2 | ||||
-rw-r--r-- | clang/test/Modules/GH80252.cppm | 4 | ||||
-rw-r--r-- | clang/test/Modules/cxx20-decls.cppm | 6 |
4 files changed, 7 insertions, 8 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 53040aa0f907..0a9cd242f9d9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -188,6 +188,9 @@ Bug Fixes to C++ Support and (`#79745 <https://github.com/llvm/llvm-project/issues/79745>`_) - Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated. Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_) +- Fix incorrect merging of modules which contain using declarations which shadow + other declarations. This could manifest as ODR checker false positives. + Fixes (`#80252 <https://github.com/llvm/llvm-project/issues/80252>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 78a04b4c6942..f3e83955c429 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -6733,7 +6733,7 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const NamedDecl *Y) const { // Using shadow declarations with the same target match. if (const auto *USX = dyn_cast<UsingShadowDecl>(X)) { const auto *USY = cast<UsingShadowDecl>(Y); - return USX->getTargetDecl() == USY->getTargetDecl(); + return declaresSameEntity(USX->getTargetDecl(), USY->getTargetDecl()); } // Using declarations with the same qualifier match. (We already know that diff --git a/clang/test/Modules/GH80252.cppm b/clang/test/Modules/GH80252.cppm index f4730a987419..dbad18dfdc7a 100644 --- a/clang/test/Modules/GH80252.cppm +++ b/clang/test/Modules/GH80252.cppm @@ -40,6 +40,4 @@ import A; import B; // Since modules are loaded lazily, force loading by performing a lookup. using xxx = bar; -// FIXME: This is a false positive ODR violation. -// 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')}} -// expected-note@bar.h:2 {{but in 'B.<global>' found constructor with 1st parameter of type 'baz::foo' (aka 'char')}} +// expected-no-diagnostics diff --git a/clang/test/Modules/cxx20-decls.cppm b/clang/test/Modules/cxx20-decls.cppm index 28af7b4bc47b..477d519b5044 100644 --- a/clang/test/Modules/cxx20-decls.cppm +++ b/clang/test/Modules/cxx20-decls.cppm @@ -31,9 +31,7 @@ using xxx = baz::foo; // CHECK-NEXT: | `-BuiltinType {{.*}} 'char' // CHECK-NEXT: |-UsingDecl {{.*}} baz::foo // CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz' -// FIXME: UsingShadowDecl should have been merged -// CHECK-NOT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} {{.*}} imported in A.<global> {{.*}} 'foo' -// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} {{.*}} imported in A.<global> {{.*}} 'foo' +// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} imported in A.<global> {{.*}} 'foo' // CHECK-LABEL: Dumping baz: // CHECK-NEXT: NamespaceDecl {{.*}} baz @@ -41,4 +39,4 @@ using xxx = baz::foo; // CHECK-NEXT: | `-BuiltinType {{.*}} 'char' // CHECK-NEXT: |-UsingDecl {{.*}} baz::foo // CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz' -// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} 'foo' +// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR]] {{.*}} 'foo' |