[PATCH] D157952: [clang] Support function pointer types with attributes when extracting parameter names for signature help
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 17 21:25:00 PDT 2023
nridge updated this revision to Diff 551374.
nridge added a comment.
Address review comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157952/new/
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
@@ -6066,12 +6066,21 @@
if (!Target)
return {};
- if (auto P = Target.getAs<PointerTypeLoc>()) {
- Target = P.getPointeeLoc();
- }
-
- if (auto P = Target.getAs<ParenTypeLoc>()) {
- Target = P.getInnerLoc();
+ // Unwrap types that may be wrapping the function type
+ while (true) {
+ if (auto P = Target.getAs<PointerTypeLoc>()) {
+ Target = P.getPointeeLoc();
+ continue;
+ }
+ if (auto A = Target.getAs<AttributedTypeLoc>()) {
+ Target = A.getModifiedLoc();
+ continue;
+ }
+ if (auto P = Target.getAs<ParenTypeLoc>()) {
+ Target = P.getInnerLoc();
+ continue;
+ }
+ break;
}
if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157952.551374.patch
Type: text/x-patch
Size: 2582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230818/b02a0e61/attachment.bin>
More information about the cfe-commits
mailing list