From f2b3f9ecc6faaf2a1cac2485b0b045ae6638767d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 24 Oct 2016 18:47:04 +0000 Subject: [PATCH] Fix crash if StmtProfile finds a type-dependent member access for which we have resolved the -> to a call to a specific operator-> function. The particular test case added here is actually being mishandled: the implicit member access should not be type-dependent (because it's accessing a non-type-dependent member of the current instantiation), but calls to a type-dependent operator-> that is a member of the current instantiation would be liable to hit the same codepath. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284999 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/StmtProfile.cpp | 6 ++++++ test/SemaTemplate/dependent-type-identity.cpp | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 9aead7b06b..cf965aa028 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -1190,6 +1190,12 @@ void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) { if (S->isTypeDependent()) { // Type-dependent operator calls are profiled like their underlying // syntactic operator. + // + // An operator call to operator-> is always implicit, so just skip it. The + // enclosing MemberExpr will profile the actual member access. + if (S->getOperator() == OO_Arrow) + return Visit(S->getArg(0)); + UnaryOperatorKind UnaryOp = UO_Extension; BinaryOperatorKind BinaryOp = BO_Comma; Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp); diff --git a/test/SemaTemplate/dependent-type-identity.cpp b/test/SemaTemplate/dependent-type-identity.cpp index 6b23a38f84..c826268c86 100644 --- a/test/SemaTemplate/dependent-type-identity.cpp +++ b/test/SemaTemplate/dependent-type-identity.cpp @@ -80,11 +80,20 @@ namespace PR6851 { S< S::cond && 1 > foo(); }; + struct Arrow { Arrow *operator->(); int n; }; + template struct M { + Arrow a; + auto f() -> Mn)>; + }; + struct Alien; bool operator&&(const Alien&, const Alien&); template S< S::cond && 1 > N::foo() { } + + template + auto M::f() -> Mn)> {} } namespace PR7460 { -- 2.40.0