[cfe-commits] r84438 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprConstant.cpp lib/Sema/SemaCXXCast.cpp test/CodeGenCXX/member-function-pointers.cpp
Anders Carlsson
andersca at mac.com
Sun Oct 18 13:31:04 PDT 2009
Author: andersca
Date: Sun Oct 18 15:31:03 2009
New Revision: 84438
URL: http://llvm.org/viewvc/llvm-project?rev=84438&view=rev
Log:
Use CK_BitCast for member function pointer casts. Fixes PR5138.
Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=84438&r1=84437&r2=84438&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Sun Oct 18 15:31:03 2009
@@ -215,6 +215,12 @@
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();
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=84438&r1=84437&r2=84438&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sun Oct 18 15:31:03 2009
@@ -542,7 +542,11 @@
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
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=84438&r1=84437&r2=84438&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Sun Oct 18 15:31:03 2009
@@ -943,6 +943,7 @@
}
// A valid member pointer cast.
+ Kind = CastExpr::CK_BitCast;
return TC_Success;
}
@@ -1044,6 +1045,7 @@
// 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 @@
// 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())
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=84438&r1=84437&r2=84438&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp Sun Oct 18 15:31:03 2009
@@ -71,3 +71,19 @@
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;
+}
More information about the cfe-commits
mailing list