================
@@ -77,6 +82,33 @@ inline const ParmVarDecl *getFunctionOrMethodParam(const 
Decl *D,
     return MD->getParamDecl(Idx);
   if (const auto *BD = dyn_cast<BlockDecl>(D))
     return BD->getParamDecl(Idx);
+
+  // Handle declarations that do not directly own parameters but have an
+  // underlying FunctionProtoType (e.g. function pointers).
+  const TypeSourceInfo *TSI = nullptr;
+  if (const auto *DD = dyn_cast<DeclaratorDecl>(D))
+    TSI = DD->getTypeSourceInfo();
+  else if (const auto *TD = dyn_cast<TypedefNameDecl>(D))
+    TSI = TD->getTypeSourceInfo();
+
+  if (!TSI)
+    return nullptr;
+
+  TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
+
+  if (auto PTL = TL.getAsAdjusted<PointerTypeLoc>())
+    TL = PTL.getPointeeLoc();
----------------
mimischly7 wrote:

Indeed the logic peels only one layer of indirection. However, I mirrored the 
TypeSourceInfo/TypeLoc hunting logic used in `Decl::getFunctionType()`, so 
using the same reasoning as in the previous comment 
(https://github.com/llvm/llvm-project/pull/210871#discussion_r3694666133), I 
think the cases handled are sufficient.

Regarding tests, the test cases I had added only checked ParamVarDecl. I have 
now added cases to check the remaining Decl types we claim to handle in 
`getFunctionOrMethodParam()` to `clang/test/Misc/attr-source-range.cpp`, and 
also created a new lit test `clang/test/Misc/attr-source-range.m` for objective 
C specific Decl's.

https://github.com/llvm/llvm-project/pull/210871
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to