[llvm-commits] [llvm-gcc-4.2] r79605 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Bill Wendling isanbard at gmail.com
Fri Aug 21 00:32:28 PDT 2009


Author: void
Date: Fri Aug 21 02:32:28 2009
New Revision: 79605

URL: http://llvm.org/viewvc/llvm-project?rev=79605&view=rev
Log:
At this point, GCC seems to have determined that the pointer's size is the same
as the sizes of the shift and the result. However, we shouldn't rely upon
this. Use the pointer's actual bit size for the integer type it should cast to.

Thanks to Eli for noticing this.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=79605&r1=79604&r2=79605&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Fri Aug 21 02:32:28 2009
@@ -3473,9 +3473,21 @@
   Value *In  = Emit(TREE_OPERAND(exp, 0), 0);
   Value *Amt = Emit(TREE_OPERAND(exp, 1), 0);
 
-  if (isa<PointerType>(In->getType()))
-    In = Builder.CreatePtrToInt(In, Amt->getType(),
+  if (isa<PointerType>(In->getType())) {
+    const Type *Ty = 0;
+
+    switch (getInt64(TYPE_SIZE (TREE_TYPE (TREE_OPERAND (exp, 0))), true)) {
+    default: assert(0 && "Pointer size in bits not a power of 2!");
+    case 1:  Ty = Type::getInt1Ty(Context);  break;
+    case 8:  Ty = Type::getInt8Ty(Context);  break;
+    case 16: Ty = Type::getInt16Ty(Context); break;
+    case 32: Ty = Type::getInt32Ty(Context); break;
+    case 64: Ty = Type::getInt64Ty(Context); break;
+    }
+
+    In = Builder.CreatePtrToInt(In, Ty,
                                 (In->getNameStr()+".cast").c_str());
+  }
 
   if (Amt->getType() != In->getType())
     Amt = Builder.CreateIntCast(Amt, In->getType(), false,





More information about the llvm-commits mailing list