[cfe-commits] r91112 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/member-function-pointers.cpp
Eli Friedman
eli.friedman at gmail.com
Fri Dec 11 01:26:30 PST 2009
Author: efriedma
Date: Fri Dec 11 03:26:29 2009
New Revision: 91112
URL: http://llvm.org/viewvc/llvm-project?rev=91112&view=rev
Log:
Move the code for converting a member pointer to a bool so that it is usable
for logical not.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=91112&r1=91111&r2=91112&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Dec 11 03:26:29 2009
@@ -38,6 +38,21 @@
/// expression and compare the result against zero, returning an Int1Ty value.
llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) {
QualType BoolTy = getContext().BoolTy;
+ if (E->getType()->isMemberFunctionPointerType()) {
+ llvm::Value *Ptr = CreateTempAlloca(ConvertType(E->getType()));
+ EmitAggExpr(E, Ptr, /*VolatileDest=*/false);
+
+ // Get the pointer.
+ llvm::Value *FuncPtr = Builder.CreateStructGEP(Ptr, 0, "src.ptr");
+ FuncPtr = Builder.CreateLoad(FuncPtr);
+
+ llvm::Value *IsNotNull =
+ Builder.CreateICmpNE(FuncPtr,
+ llvm::Constant::getNullValue(FuncPtr->getType()),
+ "tobool");
+
+ return IsNotNull;
+ }
if (!E->getType()->isAnyComplexType())
return EmitScalarConversion(EmitScalarExpr(E), E->getType(), BoolTy);
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=91112&r1=91111&r2=91112&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Dec 11 03:26:29 2009
@@ -954,34 +954,8 @@
case CastExpr::CK_FloatingCast:
return EmitScalarConversion(Visit(E), E->getType(), DestTy);
- case CastExpr::CK_MemberPointerToBoolean: {
- const MemberPointerType* T = E->getType()->getAs<MemberPointerType>();
-
- if (T->getPointeeType()->isFunctionType()) {
- // We have a member function pointer.
- llvm::Value *Ptr = CGF.CreateTempAlloca(ConvertType(E->getType()));
-
- CGF.EmitAggExpr(E, Ptr, /*VolatileDest=*/false);
-
- // Get the pointer.
- llvm::Value *FuncPtr = Builder.CreateStructGEP(Ptr, 0, "src.ptr");
- FuncPtr = Builder.CreateLoad(FuncPtr);
-
- llvm::Value *IsNotNull =
- Builder.CreateICmpNE(FuncPtr,
- llvm::Constant::getNullValue(FuncPtr->getType()),
- "tobool");
-
- return IsNotNull;
- }
-
- // We have a regular member pointer.
- Value *Ptr = Visit(const_cast<Expr*>(E));
- llvm::Value *IsNotNull =
- Builder.CreateICmpNE(Ptr, CGF.CGM.EmitNullConstant(E->getType()),
- "tobool");
- return IsNotNull;
- }
+ case CastExpr::CK_MemberPointerToBoolean:
+ return CGF.EvaluateExprAsBool(E);
}
// Handle cases where the source is an non-complex type.
Modified: cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp?rev=91112&r1=91111&r2=91112&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp Fri Dec 11 03:26:29 2009
@@ -113,3 +113,18 @@
return f == g;
}
}
+
+namespace BoolMemberPointer {
+ struct A { };
+
+ bool f(void (A::*f)()) {
+ return !f;
+ }
+
+ bool g(void (A::*f)()) {
+ if (!!f)
+ return true;
+ return false;
+ }
+}
+
More information about the cfe-commits
mailing list