aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CGExprScalar.cpp9
-rw-r--r--test/CodeGenCXX/member-pointers-zero-init.cpp13
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index d94ee5bed2..0524b44718 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -656,7 +656,14 @@ Value *ScalarExprEmitter::EmitCastExpr(const Expr *E, QualType DestTy,
CastExpr::CastKind Kind) {
if (!DestTy->isVoidType())
TestAndClearIgnoreResultAssign();
-
+
+ switch (Kind) {
+ default:
+ break;
+ case CastExpr::CK_NullToMemberPointer:
+ return CGF.CGM.EmitNullConstant(DestTy);
+ }
+
// Handle cases where the source is an non-complex type.
if (!CGF.hasAggregateLLVMType(E->getType())) {
diff --git a/test/CodeGenCXX/member-pointers-zero-init.cpp b/test/CodeGenCXX/member-pointers-zero-init.cpp
index d533600b54..e7b0fdafba 100644
--- a/test/CodeGenCXX/member-pointers-zero-init.cpp
+++ b/test/CodeGenCXX/member-pointers-zero-init.cpp
@@ -17,11 +17,18 @@ int A::* aaa[2][2];
int A::* b = 0;
void f() {
- // RUN: grep "%.* = icmp ne i64 %.*, -1" %t
+ // RUN: grep "%.* = icmp ne i64 %.*, -1" %t | count 2 &&
if (a) { }
+ if (a != 0) { }
+
+ // RUN: grep "%.* = icmp ne i64 -1, %.*" %t | count 1 &&
+ if (0 != a) { }
- // FIXME: This doesn't yet work
-// if (a != 0) { }
+ // RUN: grep "%.* = icmp eq i64 %.*, -1" %t | count 1 &&
+ if (a == 0) { }
+
+ // RUN: grep "%.* = icmp eq i64 -1, %.*" %t | count 1
+ if (0 == a) { }
}