[llvm-commits] [gcc-plugin] r81352 - /gcc-plugin/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Wed Sep 9 10:06:08 PDT 2009


Author: baldrick
Date: Wed Sep  9 12:06:08 2009
New Revision: 81352

URL: http://llvm.org/viewvc/llvm-project?rev=81352&view=rev
Log:
The pointer operand of a POINTER_PLUS_EXPR may have a trivially
different type to the return type (useless_type_conversion_p),
so fix the type with a bitcast.

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

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=81352&r1=81351&r2=81352&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Wed Sep  9 12:06:08 2009
@@ -3851,17 +3851,18 @@
   Value *Ptr = Emit(TREE_OPERAND(exp, 0), 0);
   Value *Idx = Emit(TREE_OPERAND(exp, 1), 0);
 
-  // If we are indexing over a fixed-size type, just use a GEP.
-  if (VOID_TYPE_P(TREE_TYPE(ptr_type)) || isSequentialCompatible(ptr_type))
-    return Builder.CreateInBoundsGEP(Ptr, Idx);
+  // If we are indexing over a variable sized type, do raw pointer arithmetic.
+  if (!isSequentialCompatible(ptr_type) && !VOID_TYPE_P(TREE_TYPE(ptr_type))) {
+    // Compute the offset in bytes.
+    Value *Size = Emit(TYPE_SIZE(TREE_TYPE(ptr_type)), 0);
+    Idx = Builder.CreateMul(Idx, CastToUIntType(Size, Idx->getType()));
+
+    // Convert the pointer into an i8* and add the offset to it.
+    Ptr = Builder.CreateBitCast(Ptr, Type::getInt8Ty(Context)->getPointerTo());
+  }
 
-  // Otherwise, compute the offset in bytes.
-  Value *Size = Emit(TYPE_SIZE(TREE_TYPE(ptr_type)), 0);
-  Idx = Builder.CreateMul(Idx, CastToUIntType(Size, Idx->getType()));
-
-  // Convert the pointer into an i8* and add the offset to it.
-  Ptr = Builder.CreateBitCast(Ptr, Type::getInt8Ty(Context)->getPointerTo());
-  return Builder.CreateInBoundsGEP(Ptr, Idx);
+  return Builder.CreateBitCast(Builder.CreateInBoundsGEP(Ptr, Idx),
+                               ConvertType(TREE_TYPE(exp)));
 }
 
 //===----------------------------------------------------------------------===//





More information about the llvm-commits mailing list