nridge created this revision. nridge added reviewers: hokein, kadircet, Qwinci. Herald added a subscriber: arphaman. Herald added a project: All. nridge requested review of this revision. Herald added subscribers: cfe-commits, wangpc, ilya-biryukov. Herald added projects: clang, clang-tools-extra.
Fixes https://github.com/clangd/clangd/issues/1729 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D157952 Files: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp clang/lib/Sema/SemaCodeComplete.cpp Index: clang/lib/Sema/SemaCodeComplete.cpp =================================================================== --- clang/lib/Sema/SemaCodeComplete.cpp +++ clang/lib/Sema/SemaCodeComplete.cpp @@ -6070,6 +6070,10 @@ Target = P.getPointeeLoc(); } + if (auto A = Target.getAs<AttributedTypeLoc>()) { + Target = A.getModifiedLoc(); + } + if (auto P = Target.getAs<ParenTypeLoc>()) { Target = P.getInnerLoc(); } Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -1397,20 +1397,37 @@ } TEST(SignatureHelpTest, FunctionPointers) { - auto FunctionPointerResults = signatures(R"cpp( + llvm::StringLiteral Tests[] = { + // Variable of function pointer type + R"cpp( void (*foo)(int x, int y); int main() { foo(^); } - )cpp"); - EXPECT_THAT(FunctionPointerResults.signatures, - UnorderedElementsAre(sig("([[int x]], [[int y]]) -> void"))); - - auto FunctionPointerTypedefResults = signatures(R"cpp( + )cpp", + // Wrapped in an AttributedType + R"cpp( + void (__stdcall *foo)(int x, int y); + int main() { foo(^); } + )cpp", + // Another syntax for an AttributedType + R"cpp( + void (__attribute__(stdcall) *foo)(int x, int y); + int main() { foo(^); }, + )cpp", + // Wrapped in a typedef + R"cpp( typedef void (*fn)(int x, int y); fn foo; int main() { foo(^); } - )cpp"); - EXPECT_THAT(FunctionPointerTypedefResults.signatures, - UnorderedElementsAre(sig("([[int x]], [[int y]]) -> void"))); + )cpp", + // Wrapped in both a typedef and an AttributedTyped + R"cpp( + typedef void (__stdcall *fn)(int x, int y); + fn foo; + int main() { foo(^); } + )cpp"}; + for (auto Test : Tests) + EXPECT_THAT(signatures(Test).signatures, + UnorderedElementsAre(sig("([[int x]], [[int y]]) -> void"))); } TEST(SignatureHelpTest, Constructors) {
Index: clang/lib/Sema/SemaCodeComplete.cpp =================================================================== --- clang/lib/Sema/SemaCodeComplete.cpp +++ clang/lib/Sema/SemaCodeComplete.cpp @@ -6070,6 +6070,10 @@ Target = P.getPointeeLoc(); } + if (auto A = Target.getAs<AttributedTypeLoc>()) { + Target = A.getModifiedLoc(); + } + if (auto P = Target.getAs<ParenTypeLoc>()) { Target = P.getInnerLoc(); } Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -1397,20 +1397,37 @@ } TEST(SignatureHelpTest, FunctionPointers) { - auto FunctionPointerResults = signatures(R"cpp( + llvm::StringLiteral Tests[] = { + // Variable of function pointer type + R"cpp( void (*foo)(int x, int y); int main() { foo(^); } - )cpp"); - EXPECT_THAT(FunctionPointerResults.signatures, - UnorderedElementsAre(sig("([[int x]], [[int y]]) -> void"))); - - auto FunctionPointerTypedefResults = signatures(R"cpp( + )cpp", + // Wrapped in an AttributedType + R"cpp( + void (__stdcall *foo)(int x, int y); + int main() { foo(^); } + )cpp", + // Another syntax for an AttributedType + R"cpp( + void (__attribute__(stdcall) *foo)(int x, int y); + int main() { foo(^); }, + )cpp", + // Wrapped in a typedef + R"cpp( typedef void (*fn)(int x, int y); fn foo; int main() { foo(^); } - )cpp"); - EXPECT_THAT(FunctionPointerTypedefResults.signatures, - UnorderedElementsAre(sig("([[int x]], [[int y]]) -> void"))); + )cpp", + // Wrapped in both a typedef and an AttributedTyped + R"cpp( + typedef void (__stdcall *fn)(int x, int y); + fn foo; + int main() { foo(^); } + )cpp"}; + for (auto Test : Tests) + EXPECT_THAT(signatures(Test).signatures, + UnorderedElementsAre(sig("([[int x]], [[int y]]) -> void"))); } TEST(SignatureHelpTest, Constructors) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits