llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-modules @llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) <details> <summary>Changes</summary> [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 fd8634a09de71. This problem could manifest itself as ODR check false positives when importing modules. Fixes: #ISSUE_TO_BE_CREATED --- Full diff: https://github.com/llvm/llvm-project/pull/80245.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+3) - (modified) clang/lib/AST/ASTContext.cpp (+1-1) - (added) clang/test/Modules/cxx20-decls.cppm (+42) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b7b11ab3a6b2e..aa14b8e931101 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -181,6 +181,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 (`#TODO <https://github.com/llvm/llvm-project/issues/TODO>`_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 71c9c0003d18c..feeb350bf3e0c 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -6732,7 +6732,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/cxx20-decls.cppm b/clang/test/Modules/cxx20-decls.cppm new file mode 100644 index 0000000000000..ee9f117278884 --- /dev/null +++ b/clang/test/Modules/cxx20-decls.cppm @@ -0,0 +1,42 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: cd %t +// +// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o %t/A.pcm -verify +// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm -fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s + +//--- foo.h +namespace baz { + using foo = char; + using baz::foo; +} + +//--- A.cppm +// expected-no-diagnostics +module; +#include "foo.h" +export module A; + +//--- B.cpp +// expected-no-diagnostics +#include "foo.h" +import A; +// Since modules are loaded lazily, force loading by performing a lookup. +using xxx = baz::foo; + +// CHECK-LABEL: Dumping baz: +// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ ]*]] <{{.*}}> line:{{.*}} imported in A.<global> hidden <undeserialized declarations> baz +// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz' +// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A.<global> hidden foo 'char' +// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char' +// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A.<global> hidden baz::foo +// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz' +// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A.<global> hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo' + +// CHECK-LABEL: Dumping baz: +// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz +// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced foo 'char' +// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char' +// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo +// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz' +// CHECK-NEXT: `-UsingShadowDecl 0x[[SHADOW_ADDR]] <{{.*}}> col:{{.*}} implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo' `````````` </details> https://github.com/llvm/llvm-project/pull/80245 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits