[cfe-commits] r134813 - /cfe/trunk/lib/CodeGen/CGDecl.cpp

John McCall rjmccall at apple.com
Sat Jul 9 02:09:00 PDT 2011


Author: rjmccall
Date: Sat Jul  9 04:09:00 2011
New Revision: 134813

URL: http://llvm.org/viewvc/llvm-project?rev=134813&view=rev
Log:
More compiler workarounds.  I have to admit that I was not
expecting so much concentrated oddity on what seemed like a
trivial feature.  Thanks to François Pichet for doing the
MSVC legwork here.


Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=134813&r1=134812&r2=134813&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Jul  9 04:09:00 2011
@@ -1099,13 +1099,23 @@
 
 CodeGenFunction::Destroyer &
 CodeGenFunction::getDestroyer(QualType::DestructionKind kind) {
-  // GCC 4.2 requires the *& on these function references.
+  // This is surprisingly compiler-dependent.  GCC 4.2 can't bind
+  // references to functions directly in returns, and using '*&foo'
+  // confuses MSVC.  Luckily, the following code pattern works in both.
+  Destroyer *destroyer = 0;
   switch (kind) {
   case QualType::DK_none: llvm_unreachable("no destroyer for trivial dtor");
-  case QualType::DK_cxx_destructor: return *&destroyCXXObject;
-  case QualType::DK_objc_strong_lifetime: return *&destroyARCStrongPrecise;
-  case QualType::DK_objc_weak_lifetime: return *&destroyARCWeak;
+  case QualType::DK_cxx_destructor:
+    destroyer = &destroyCXXObject;
+    break;
+  case QualType::DK_objc_strong_lifetime:
+    destroyer = &destroyARCStrongPrecise;
+    break;
+  case QualType::DK_objc_weak_lifetime:
+    destroyer = &destroyARCWeak;
+    break;
   }
+  return *destroyer;
 }
 
 void CodeGenFunction::pushDestroy(CleanupKind cleanupKind, llvm::Value *addr,





More information about the cfe-commits mailing list