[llvm-commits] [gcc-plugin] r81854 - /gcc-plugin/trunk/llvm-convert.cpp
Duncan Sands
baldrick at free.fr
Tue Sep 15 06:03:26 PDT 2009
Author: baldrick
Date: Tue Sep 15 08:03:25 2009
New Revision: 81854
URL: http://llvm.org/viewvc/llvm-project?rev=81854&view=rev
Log:
It turns out that POINTER_PLUS_EXPR means to add a byte offset to the pointer,
and not compute ptr+offset (i.e. in units of the pointee) as you might think.
With this fix, sqlite3 not only compiles and links, it actually works!
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=81854&r1=81853&r2=81854&view=diff
==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Tue Sep 15 08:03:25 2009
@@ -3758,22 +3758,15 @@
}
Value *TreeToLLVM::EmitPOINTER_PLUS_EXPR(tree exp) {
- tree ptr_type = TREE_TYPE(TREE_OPERAND(exp, 0));
- Value *Ptr = Emit(TREE_OPERAND(exp, 0), 0);
- Value *Idx = Emit(TREE_OPERAND(exp, 1), 0);
-
- // 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());
- }
+ Value *Ptr = Emit(TREE_OPERAND(exp, 0), 0); // The pointer.
+ Value *Idx = Emit(TREE_OPERAND(exp, 1), 0); // The offset in bytes.
+ // Convert the pointer into an i8* and add the offset to it.
+ Ptr = Builder.CreateBitCast(Ptr, Type::getInt8Ty(Context)->getPointerTo());
Value *GEP = POINTER_TYPE_OVERFLOW_UNDEFINED ?
Builder.CreateInBoundsGEP(Ptr, Idx) : Builder.CreateGEP(Ptr, Idx);
+
+ // The result may be of a different pointer type.
return Builder.CreateBitCast(GEP, ConvertType(TREE_TYPE(exp)));
}
More information about the llvm-commits
mailing list