diff options
author | Alp Toker <alp@nuanti.com> | 2014-07-02 12:55:58 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-07-02 12:55:58 +0000 |
commit | f5b107940ab1d302ac4ad48a92d8d95bb7af9676 (patch) | |
tree | 55ade4de16a7648ff7fcda74e3169f3d1b17a37d /clang/lib/AST/Decl.cpp | |
parent | 1471cb17ae927537b59308eead61e0855d307d5f (diff) | |
download | bcm5719-llvm-f5b107940ab1d302ac4ad48a92d8d95bb7af9676.tar.gz bcm5719-llvm-f5b107940ab1d302ac4ad48a92d8d95bb7af9676.zip |
Make FunctionDecl::getReturnTypeSourceRange() support non-builtin types
Also document that the function is a "best-effort" facility to extract source
ranges from limited AST type location info.
llvm-svn: 212174
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 702a2e32e3e..fdf94a8ad5e 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2691,17 +2691,20 @@ SourceRange FunctionDecl::getReturnTypeSourceRange() const { const TypeSourceInfo *TSI = getTypeSourceInfo(); if (!TSI) return SourceRange(); - - TypeLoc TL = TSI->getTypeLoc(); - FunctionTypeLoc FunctionTL = TL.getAs<FunctionTypeLoc>(); - if (!FunctionTL) + FunctionTypeLoc FTL = + TSI->getTypeLoc().IgnoreParens().getAs<FunctionTypeLoc>(); + if (!FTL) return SourceRange(); - TypeLoc ResultTL = FunctionTL.getReturnLoc(); - if (ResultTL.getUnqualifiedLoc().getAs<BuiltinTypeLoc>()) - return ResultTL.getSourceRange(); + // Skip self-referential return types. + const SourceManager &SM = getASTContext().getSourceManager(); + SourceRange RTRange = FTL.getReturnLoc().getSourceRange(); + SourceLocation Boundary = getNameInfo().getLocStart(); + if (RTRange.isInvalid() || Boundary.isInvalid() || + !SM.isBeforeInTranslationUnit(RTRange.getEnd(), Boundary)) + return SourceRange(); - return SourceRange(); + return RTRange; } /// \brief For an inline function definition in C, or for a gnu_inline function |