diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-03 20:00:27 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-03 20:00:27 +0000 |
commit | e174bd05ca9991e705f51afcfab27933b537dc63 (patch) | |
tree | 9869b4cef5523183dabddaf39f58ead228011d50 | |
parent | 324b54d3f60d92a82815512119791ce1c285b63e (diff) |
If we're generating code to create a pointer-to-member function
aggregate and the result of the aggregate is unused, bail out
early. Fixes PR7027.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102942 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 6 | ||||
-rw-r--r-- | test/CodeGenCXX/member-function-pointers.cpp | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index d2f75bd355..d1b0dff11e 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -321,6 +321,11 @@ void AggExprEmitter::VisitUnaryAddrOf(const UnaryOperator *E) { (void) MPT; assert(MPT->getPointeeType()->isFunctionProtoType() && "Unexpected member pointer type!"); + + // The creation of member function pointers has no side effects; if + // there is no destination pointer, we have nothing to do. + if (!DestPtr) + return; const DeclRefExpr *DRE = cast<DeclRefExpr>(E->getSubExpr()); const CXXMethodDecl *MD = @@ -329,6 +334,7 @@ void AggExprEmitter::VisitUnaryAddrOf(const UnaryOperator *E) { const llvm::Type *PtrDiffTy = CGF.ConvertType(CGF.getContext().getPointerDiffType()); + llvm::Value *DstPtr = Builder.CreateStructGEP(DestPtr, 0, "dst.ptr"); llvm::Value *FuncPtr; diff --git a/test/CodeGenCXX/member-function-pointers.cpp b/test/CodeGenCXX/member-function-pointers.cpp index a1f4daec8e..e4beee15bb 100644 --- a/test/CodeGenCXX/member-function-pointers.cpp +++ b/test/CodeGenCXX/member-function-pointers.cpp @@ -184,3 +184,9 @@ namespace PR6258 { void (A::*pf)(bool) = &A::f; } } + +// PR7027 +namespace PR7027 { + struct X { void test( ); }; + void testX() { &X::test; } +} |