[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 22 07:16:51 PDT 2025
================
@@ -1638,43 +1647,6 @@ CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
return {nullptr, nullptr};
}
-SourceLocation CallExpr::getBeginLoc() const {
- if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
- return OCE->getBeginLoc();
-
- // A non-dependent call to a member function with an explicit object parameter
- // is modelled with the object expression being the first argument, e.g. in
- // `o.f(x)`, the callee will be just `f`, and `o` will be the first argument.
- // Since the first argument is written before the callee, the expression's
- // begin location should come from the first argument.
- // This does not apply to dependent calls, which are modelled with `o.f`
- // being the callee.
- if (!isTypeDependent()) {
- if (const auto *Method =
- dyn_cast_if_present<const CXXMethodDecl>(getCalleeDecl());
- Method && Method->isExplicitObjectMemberFunction()) {
- if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
- return FirstArgLoc;
- }
- }
- }
-
- SourceLocation begin = getCallee()->getBeginLoc();
- if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
- begin = getArg(0)->getBeginLoc();
- return begin;
-}
-
-SourceLocation CallExpr::getEndLoc() const {
- if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
- return OCE->getEndLoc();
-
- SourceLocation end = getRParenLoc();
- if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
- end = getArg(getNumArgs() - 1)->getEndLoc();
----------------
cor3ntin wrote:
No test broke, no. Afaict, getExprLoc calls the implementation in CXXOperatorCallExpr
https://github.com/llvm/llvm-project/pull/141058
More information about the cfe-commits
mailing list