[llvm-commits] [dragonegg] r155123 - /dragonegg/trunk/src/Constants.cpp

Duncan Sands baldrick at free.fr
Thu Apr 19 05:47:28 PDT 2012


Author: baldrick
Date: Thu Apr 19 07:47:28 2012
New Revision: 155123

URL: http://llvm.org/viewvc/llvm-project?rev=155123&view=rev
Log:
Add support for taking the address of a constant MEM_REF, as gcc-4.7 generates
these for vtable pointers, for example on dtors-in-dtor-cfg-output.cpp from the
clang testsuite.

Modified:
    dragonegg/trunk/src/Constants.cpp

Modified: dragonegg/trunk/src/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Constants.cpp?rev=155123&r1=155122&r2=155123&view=diff
==============================================================================
--- dragonegg/trunk/src/Constants.cpp (original)
+++ dragonegg/trunk/src/Constants.cpp Thu Apr 19 07:47:28 2012
@@ -1611,6 +1611,23 @@
   return TheTreeToLLVM->AddressOfLABEL_DECL(exp);
 }
 
+#if (GCC_MINOR > 5)
+/// AddressOfMEM_REF - Return the address of a memory reference.
+static Constant *AddressOfMEM_REF(tree exp, TargetFolder &Folder) {
+  // The address is the first operand offset in bytes by the second.
+  Constant *Addr = getAsRegister(TREE_OPERAND(exp, 0), Folder);
+  if (integer_zerop(TREE_OPERAND(exp, 1)))
+    return Addr;
+
+  // Convert to a byte pointer and displace by the offset.
+  Addr = Folder.CreateBitCast(Addr, GetUnitPointerType(Context));
+  APInt Delta = getIntegerValue(TREE_OPERAND(exp, 1));
+  Constant *Offset = ConstantInt::get(Context, Delta);
+  // The address is always inside the referenced object, so "inbounds".
+  return Folder.CreateInBoundsGetElementPtr(Addr, Offset);
+}
+#endif
+
 /// AddressOfImpl - Implementation of AddressOf.
 static Constant *AddressOfImpl(tree exp, TargetFolder &Folder) {
   Constant *Addr;
@@ -1651,6 +1668,11 @@
   case LABEL_DECL:
     Addr = AddressOfLABEL_DECL(exp, Folder);
     break;
+#if (GCC_MINOR > 5)
+  case MEM_REF:
+    Addr = AddressOfMEM_REF(exp, Folder);
+    break;
+#endif
   }
 
   // Ensure that the address has the expected type.  It is simpler to do this





More information about the llvm-commits mailing list