kbobyrev created this revision. kbobyrev added a reviewer: hokein. Herald added subscribers: usaxena95, arphaman. kbobyrev requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang.
This is a fix of the problem (rather than a patch - D96247 <https://reviews.llvm.org/D96247>) discussed in https://github.com/clangd/clangd/issues/685. Fixes: https://github.com/clangd/clangd/issues/685 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96324 Files: clang-tools-extra/clangd/refactor/Rename.cpp clang-tools-extra/clangd/unittests/RenameTests.cpp Index: clang-tools-extra/clangd/unittests/RenameTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/RenameTests.cpp +++ clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -678,6 +678,34 @@ } )cpp", + // Function argument. + R"cpp( + void foo(int [[Bar^]]); + void foo(int [[Bar^]]); + + void foo(int [[Bar^]]) { + } + )cpp", + + // Template function argument. + R"cpp( + template <typename T> + void foo(T [[Bar^]]); + + template <typename T> + void foo(T [[Bar^]]) {} + )cpp", + R"cpp( + template <typename T> + void foo(T [[Bar^]]); + + template <typename T> + void foo(T [[Bar^]]) {} + + template <> + void foo(int [[Bar^]]) {} + )cpp", + // Namespace alias. R"cpp( namespace a { namespace b { void foo(); } } @@ -1089,6 +1117,15 @@ )cpp", "conflict", !HeaderFile, nullptr, "Conflict"}, + {R"cpp( + void func(int V^ar); + + void func(int Var) { + bool Conflict; + } + )cpp", + "conflict", !HeaderFile, nullptr, "Conflict"}, + {R"cpp( void func(int V^ar, int Conflict) { } Index: clang-tools-extra/clangd/refactor/Rename.cpp =================================================================== --- clang-tools-extra/clangd/refactor/Rename.cpp +++ clang-tools-extra/clangd/refactor/Rename.cpp @@ -151,6 +151,20 @@ if (const auto *VD = dyn_cast<VarDecl>(D)) { if (const VarDecl *OriginalVD = VD->getInstantiatedFromStaticDataMember()) VD = OriginalVD; + // Arguments are canonicalized to their function's canonical function + // arguments. + if (const auto *Argument = dyn_cast<ParmVarDecl>(VD)) { + if (const auto *Function = + dyn_cast<FunctionDecl>(Argument->getDeclContext())) { + // FIXME(kirillbobyrev): This excludes constructors: their canonical + // decls are canonicalized RecordDecls. + if (const auto *Canonical = + dyn_cast<FunctionDecl>(canonicalRenameDecl(Function))) { + return Canonical->getParamDecl(Argument->getFunctionScopeIndex()) + ->getCanonicalDecl(); + } + } + } return VD->getCanonicalDecl(); } return dyn_cast<NamedDecl>(D->getCanonicalDecl());
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/RenameTests.cpp +++ clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -678,6 +678,34 @@ } )cpp", + // Function argument. + R"cpp( + void foo(int [[Bar^]]); + void foo(int [[Bar^]]); + + void foo(int [[Bar^]]) { + } + )cpp", + + // Template function argument. + R"cpp( + template <typename T> + void foo(T [[Bar^]]); + + template <typename T> + void foo(T [[Bar^]]) {} + )cpp", + R"cpp( + template <typename T> + void foo(T [[Bar^]]); + + template <typename T> + void foo(T [[Bar^]]) {} + + template <> + void foo(int [[Bar^]]) {} + )cpp", + // Namespace alias. R"cpp( namespace a { namespace b { void foo(); } } @@ -1089,6 +1117,15 @@ )cpp", "conflict", !HeaderFile, nullptr, "Conflict"}, + {R"cpp( + void func(int V^ar); + + void func(int Var) { + bool Conflict; + } + )cpp", + "conflict", !HeaderFile, nullptr, "Conflict"}, + {R"cpp( void func(int V^ar, int Conflict) { } Index: clang-tools-extra/clangd/refactor/Rename.cpp =================================================================== --- clang-tools-extra/clangd/refactor/Rename.cpp +++ clang-tools-extra/clangd/refactor/Rename.cpp @@ -151,6 +151,20 @@ if (const auto *VD = dyn_cast<VarDecl>(D)) { if (const VarDecl *OriginalVD = VD->getInstantiatedFromStaticDataMember()) VD = OriginalVD; + // Arguments are canonicalized to their function's canonical function + // arguments. + if (const auto *Argument = dyn_cast<ParmVarDecl>(VD)) { + if (const auto *Function = + dyn_cast<FunctionDecl>(Argument->getDeclContext())) { + // FIXME(kirillbobyrev): This excludes constructors: their canonical + // decls are canonicalized RecordDecls. + if (const auto *Canonical = + dyn_cast<FunctionDecl>(canonicalRenameDecl(Function))) { + return Canonical->getParamDecl(Argument->getFunctionScopeIndex()) + ->getCanonicalDecl(); + } + } + } return VD->getCanonicalDecl(); } return dyn_cast<NamedDecl>(D->getCanonicalDecl());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits