[PATCH] D95244: [clang][AST] Handle overload callee type in CallExpr::getCallReturnType.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 23 08:42:32 PDT 2021
balazske updated this revision to Diff 332686.
balazske added a comment.
Fixed according to the comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95244/new/
https://reviews.llvm.org/D95244
Files:
clang/lib/AST/Expr.cpp
clang/unittests/Tooling/SourceCodeTest.cpp
Index: clang/unittests/Tooling/SourceCodeTest.cpp
===================================================================
--- clang/unittests/Tooling/SourceCodeTest.cpp
+++ clang/unittests/Tooling/SourceCodeTest.cpp
@@ -621,4 +621,63 @@
};
Visitor.runOver(Code);
}
+
+TEST(SourceCodeTest, GetCallReturnType_Callee_UnresolvedLookupExpr) {
+ llvm::StringRef Code = R"cpp(
+template<class T, class F>
+void templ(const T& t, F f) {
+ f(t);
+ // CalleeType in getCallReturntype is Overload and dependent
+}
+int f_overload(int) { return 1; }
+int f_overload(double) { return 2; }
+
+void f() {
+ int i = 0;
+ templ(i, [](const auto &p) {
+ f_overload(p); // UnresolvedLookupExpr
+ // CalleeType in getCallReturntype is Overload and not dependent
+ });
+}
+)cpp";
+
+ CallsVisitor Visitor;
+ Visitor.OnCall = [](CallExpr *Expr, ASTContext *Context) {
+ // Should not crash.
+ (void)Expr->getCallReturnType(*Context);
+ };
+ Visitor.runOver(Code, CallsVisitor::Lang_CXX14);
+}
+
+TEST(SourceCodeTest, GetCallReturnType_Callee_UnresolvedMemberExpr) {
+ llvm::StringRef Code = R"cpp(
+template<class T, class F>
+void templ(const T& t, F f) {
+ f(t);
+ // CalleeType in getCallReturntype is Overload and dependent
+}
+
+struct A {
+ void f_overload(int);
+ void f_overload(double);
+};
+
+void f() {
+ int i = 0;
+ templ(i, [](const auto &p) {
+ A a;
+ a.f_overload(p); // UnresolvedMemberExpr
+ // CalleeType in getCallReturntype is BoundMember and has overloads
+ });
+}
+)cpp";
+
+ CallsVisitor Visitor;
+ Visitor.OnCall = [](CallExpr *Expr, ASTContext *Context) {
+ // Should not crash.
+ (void)Expr->getCallReturnType(*Context);
+ };
+ Visitor.runOver(Code, CallsVisitor::Lang_CXX14);
+}
+
} // end anonymous namespace
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1383,6 +1383,7 @@
QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const {
const Expr *Callee = getCallee();
QualType CalleeType = Callee->getType();
+
if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) {
CalleeType = FnTypePtr->getPointeeType();
} else if (const auto *BPT = CalleeType->getAs<BlockPointerType>()) {
@@ -1391,8 +1392,16 @@
if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens()))
return Ctx.VoidTy;
+ if (isa<UnresolvedMemberExpr>(Callee->IgnoreParens()))
+ return Ctx.DependentTy;
+
// This should never be overloaded and so should never return null.
CalleeType = Expr::findBoundMemberType(Callee);
+ assert(!CalleeType.isNull());
+
+ } else if (CalleeType->isDependentType() ||
+ CalleeType->isSpecificPlaceholderType(BuiltinType::Overload)) {
+ return Ctx.DependentTy;
}
const FunctionType *FnType = CalleeType->castAs<FunctionType>();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95244.332686.patch
Type: text/x-patch
Size: 2881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210323/18444e87/attachment.bin>
More information about the cfe-commits
mailing list