Index: clang/include/clang/AST/Decl.h =================================================================== --- clang/include/clang/AST/Decl.h +++ clang/include/clang/AST/Decl.h @@ -2327,6 +2327,10 @@ /// limited representation in the AST. SourceRange getReturnTypeSourceRange() const; + /// Attempt to compute an informative source range covering the + /// function parameters. This omits the ellipsis of a variadic function. + SourceRange getParametersSourceRange() const; + /// Get the declared return type, which may differ from the actual return /// type if the return type is deduced. QualType getDeclaredReturnType() const { Index: clang/lib/AST/Decl.cpp =================================================================== --- clang/lib/AST/Decl.cpp +++ clang/lib/AST/Decl.cpp @@ -3301,6 +3301,17 @@ return RTRange; } +SourceRange FunctionDecl::getParametersSourceRange() const { + auto NP = getNumParams(); + if (NP == 0) + return SourceRange(); + + auto Begin = ParamInfo[0]->getSourceRange().getBegin(); + auto End = ParamInfo[NP - 1]->getSourceRange().getEnd(); + + return SourceRange(Begin, End); +} + SourceRange FunctionDecl::getExceptionSpecSourceRange() const { const TypeSourceInfo *TSI = getTypeSourceInfo(); if (!TSI) Index: clang/unittests/AST/SourceLocationTest.cpp =================================================================== --- clang/unittests/AST/SourceLocationTest.cpp +++ clang/unittests/AST/SourceLocationTest.cpp @@ -648,6 +648,32 @@ Language::Lang_CXX11)); } +class FunctionDeclParametersRangeVerifier : public RangeVerifier { +protected: + SourceRange getRange(const FunctionDecl &Function) override { + return Function.getParametersSourceRange(); + } +}; + +TEST(FunctionDeclParameters, FunctionDeclSingleParameter) { + FunctionDeclParametersRangeVerifier Verifier; + Verifier.expectRange(1, 8, 1, 12); + EXPECT_TRUE(Verifier.match("void f(int a);\n", functionDecl())); +} + +TEST(FunctionDeclParameters, FunctionDeclMultipleParameters) { + FunctionDeclParametersRangeVerifier Verifier; + Verifier.expectRange(1, 8, 1, 28); + EXPECT_TRUE( + Verifier.match("void f(int a, int b, char *c);\n", functionDecl())); +} + +TEST(FunctionDeclParameters, FunctionDeclWithDefaultValue) { + FunctionDeclParametersRangeVerifier Verifier; + Verifier.expectRange(1, 8, 1, 16); + EXPECT_TRUE(Verifier.match("void f(int a = 5);\n", functionDecl())); +} + TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) { RangeVerifier Verifier; Verifier.expectRange(2, 1, 2, 16);