[cfe-commits] r123863 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaExprCXX.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaOverload.cpp test/SemaCXX/ambig-user-defined-conversions.cpp
Douglas Gregor
dgregor at apple.com
Wed Jan 19 16:18:05 PST 2011
Author: dgregor
Date: Wed Jan 19 18:18:04 2011
New Revision: 123863
URL: http://llvm.org/viewvc/llvm-project?rev=123863&view=rev
Log:
Sema::BuildCXXMemberCallExpr() can fail due to access or ambiguities,
so allow it to propagate the failure outward. Fixes the crashing part
of <rdar://problem/8876150>.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=123863&r1=123862&r2=123863&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Jan 19 18:18:04 2011
@@ -2489,9 +2489,8 @@
Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
TypeSourceInfo *EncodedTypeInfo,
SourceLocation RParenLoc);
- CXXMemberCallExpr *BuildCXXMemberCallExpr(Expr *Exp,
- NamedDecl *FoundDecl,
- CXXMethodDecl *Method);
+ ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
+ CXXMethodDecl *Method);
ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
SourceLocation EncodeLoc,
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=123863&r1=123862&r2=123863&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Jan 19 18:18:04 2011
@@ -1718,8 +1718,11 @@
// Create an implicit call expr that calls it.
// FIXME: pass the FoundDecl for the user-defined conversion here
- CXXMemberCallExpr *CE = S.BuildCXXMemberCallExpr(From, Method, Method);
- return S.MaybeBindToTemporary(CE);
+ ExprResult Result = S.BuildCXXMemberCallExpr(From, Method, Method);
+ if (Result.isInvalid())
+ return ExprError();
+
+ return S.MaybeBindToTemporary(Result.get());
}
}
}
@@ -3592,12 +3595,11 @@
Destructed, HasTrailingLParen);
}
-CXXMemberCallExpr *Sema::BuildCXXMemberCallExpr(Expr *Exp,
- NamedDecl *FoundDecl,
- CXXMethodDecl *Method) {
+ExprResult Sema::BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl,
+ CXXMethodDecl *Method) {
if (PerformObjectArgumentInitialization(Exp, /*Qualifier=*/0,
FoundDecl, Method))
- assert(0 && "Calling BuildCXXMemberCallExpr with invalid call?");
+ return true;
MemberExpr *ME =
new (Context) MemberExpr(Exp, /*IsArrow=*/false, Method,
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=123863&r1=123862&r2=123863&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jan 19 18:18:04 2011
@@ -3788,8 +3788,7 @@
CurInit.release();
// Build the actual call to the conversion function.
- CurInit = S.Owned(S.BuildCXXMemberCallExpr(CurInitExpr, FoundFn,
- Conversion));
+ CurInit = S.BuildCXXMemberCallExpr(CurInitExpr, FoundFn, Conversion);
if (CurInit.isInvalid() || !CurInit.get())
return ExprError();
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=123863&r1=123862&r2=123863&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Jan 19 18:18:04 2011
@@ -3438,7 +3438,11 @@
return ExprError();
CheckMemberOperatorAccess(From->getExprLoc(), From, 0, Found);
- From = BuildCXXMemberCallExpr(From, Found, Conversion);
+ ExprResult Result = BuildCXXMemberCallExpr(From, Found, Conversion);
+ if (Result.isInvalid())
+ return ExprError();
+
+ From = Result.get();
}
// We'll complain below about a non-integral condition type.
@@ -3461,8 +3465,12 @@
<< T << ConvTy->isEnumeralType() << ConvTy << From->getSourceRange();
}
- From = BuildCXXMemberCallExpr(From, Found,
+ ExprResult Result = BuildCXXMemberCallExpr(From, Found,
cast<CXXConversionDecl>(Found->getUnderlyingDecl()));
+ if (Result.isInvalid())
+ return ExprError();
+
+ From = Result.get();
break;
}
@@ -8162,10 +8170,11 @@
// Create an implicit member expr to refer to the conversion operator.
// and then call it.
- CXXMemberCallExpr *CE = BuildCXXMemberCallExpr(Object, Best->FoundDecl,
- Conv);
-
- return ActOnCallExpr(S, CE, LParenLoc, MultiExprArg(Args, NumArgs),
+ ExprResult Call = BuildCXXMemberCallExpr(Object, Best->FoundDecl, Conv);
+ if (Call.isInvalid())
+ return ExprError();
+
+ return ActOnCallExpr(S, Call.get(), LParenLoc, MultiExprArg(Args, NumArgs),
RParenLoc);
}
Modified: cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp?rev=123863&r1=123862&r2=123863&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp (original)
+++ cfe/trunk/test/SemaCXX/ambig-user-defined-conversions.cpp Wed Jan 19 18:18:04 2011
@@ -57,3 +57,11 @@
}
}
+namespace rdar8876150 {
+ struct A { operator bool(); };
+ struct B : A { };
+ struct C : A { };
+ struct D : B, C { };
+
+ bool f(D d) { return !d; } // expected-error{{ambiguous conversion from derived class 'rdar8876150::D' to base class 'rdar8876150::A':}}
+}
More information about the cfe-commits
mailing list