Fix LLVM C API for DataLayout
[oota-llvm.git] / lib / Target / TargetMachineC.cpp
index 6255448a7e3c5ba21076d359fbde0bff8e10aa42..f82566c37baa43c4d237fdffd8f720514ac526d1 100644 (file)
 
 using namespace llvm;
 
+namespace llvm {
+// Friend to the TargetMachine, access legacy API that are made private in C++
+struct C_API_PRIVATE_ACCESS {
+  static const DataLayout &getDataLayout(const TargetMachine &T) {
+    return T.getDataLayout();
+  }
+};
+}
+
 static TargetMachine *unwrap(LLVMTargetMachineRef P) {
   return reinterpret_cast<TargetMachine *>(P);
 }
@@ -168,7 +177,7 @@ char* LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T) {
 
 /** Deprecated: use LLVMGetDataLayout(LLVMModuleRef M) instead. */
 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
-  return wrap(&unwrap(T)->getDataLayout());
+  return wrap(&C_API_PRIVATE_ACCESS::getDataLayout(*unwrap(T)));
 }
 
 void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,