summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-10-18 20:31:03 +0000
committerAnders Carlsson <andersca@mac.com>2009-10-18 20:31:03 +0000
commit9500ad13b0b22bc5e8730aa1d3472f9f5349fefd (patch)
treeaf9b821b4c68eb992de8452a74adfe73b92151e5
parent70e7eadd15506498a909b3ea2bd984e987cc2667 (diff)
downloadbcm5719-llvm-9500ad13b0b22bc5e8730aa1d3472f9f5349fefd.tar.gz
bcm5719-llvm-9500ad13b0b22bc5e8730aa1d3472f9f5349fefd.zip
Use CK_BitCast for member function pointer casts. Fixes PR5138.
llvm-svn: 84438
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp6
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp6
-rw-r--r--clang/lib/Sema/SemaCXXCast.cpp6
-rw-r--r--clang/test/CodeGenCXX/member-function-pointers.cpp16
4 files changed, 32 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 88fdb542f3c..066029f9a53 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -215,6 +215,12 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
break;
}
+ case CastExpr::CK_BitCast: {
+ // This must be a member function pointer cast.
+ Visit(E->getSubExpr());
+ break;
+ }
+
case CastExpr::CK_BaseToDerivedMemberPointer: {
QualType SrcType = E->getSubExpr()->getType();
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 7f540c3c068..fc3748c8e3c 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -542,7 +542,11 @@ public:
return CS;
}
}
-
+
+ case CastExpr::CK_BitCast:
+ // This must be a member function pointer cast.
+ return Visit(E->getSubExpr());
+
default: {
// FIXME: This should be handled by the CK_NoOp cast kind.
// Explicit and implicit no-op casts
diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp
index 69d1f92a083..ef1d128f63d 100644
--- a/clang/lib/Sema/SemaCXXCast.cpp
+++ b/clang/lib/Sema/SemaCXXCast.cpp
@@ -943,6 +943,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr,
}
// A valid member pointer cast.
+ Kind = CastExpr::CK_BitCast;
return TC_Success;
}
@@ -1044,6 +1045,7 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr,
// Not casting away constness, so the only remaining check is for compatible
// pointer categories.
+ Kind = CastExpr::CK_BitCast;
if (SrcType->isFunctionPointerType()) {
if (DestType->isFunctionPointerType()) {
@@ -1085,8 +1087,10 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr,
// This test is outside everything else because it's the only case where
// a non-lvalue-reference target type does not lead to decay.
// C++ 5.2.9p4: Any expression can be explicitly converted to type "cv void".
- if (CastTy->isVoidType())
+ if (CastTy->isVoidType()) {
+ Kind = CastExpr::CK_ToVoid;
return false;
+ }
// If the type is dependent, we won't do any other semantic analysis now.
if (CastTy->isDependentType() || CastExpr->isTypeDependent())
diff --git a/clang/test/CodeGenCXX/member-function-pointers.cpp b/clang/test/CodeGenCXX/member-function-pointers.cpp
index 13f7de5a631..a7c21133d05 100644
--- a/clang/test/CodeGenCXX/member-function-pointers.cpp
+++ b/clang/test/CodeGenCXX/member-function-pointers.cpp
@@ -71,3 +71,19 @@ namespace PR5177 {
void bar(B1 b2) { while (b2()) ; }
}
+
+// PR5138
+namespace PR5138 {
+ struct foo {
+ virtual void bar(foo *);
+ };
+
+ extern "C" {
+ void baz(foo *);
+ }
+
+ void (foo::*ptr1)(void *) = (void (foo::*)(void *))&foo::bar;
+ void (*ptr2)(void *) = (void (*)(void *))&baz;
+
+ void (foo::*ptr3)(void) = (void (foo::*)(void))&foo::bar;
+}
OpenPOWER on IntegriCloud