Gabriel Quadros
2012-Jun-03 20:23 UTC
[LLVMdev] Constant::getAllOnesValue(): expected behaviour or bug?
Hi, I was playing with the Constant::getAllOnesValue() method and found that it doesn't handlesPointerTypes correctly. When receiving a "i32*" argument, it was returning with some big integer vector, such as <12113216 x i32>. When you call this method passing a PointerType, the following code is executed: 00152 VectorType *VTy = cast<VectorType>(Ty);00153 return ConstantVector::getSplat(VTy->getNumElements(),00154 getAllOnesValue(VTy->getElementType() When VTy->getNumElements() is called, it returns the value of the instance variable NumElementspresent in VectorType objects, but we passed in a PointerType (SequentialType), which doesn't havethis variable but have at the same position one variable representing the type of the pointed thing. 00309 class SequentialType : public CompositeType {00310 Type *ContainedType; So getNumElements() will return some part of the value of ContainedType (an address), whichexplains that big integer vectors. Do you think this is an expected behaviour or a bug? Regards,Gabriel -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120603/0f01acce/attachment.html>
Duncan Sands
2012-Jun-04 07:21 UTC
[LLVMdev] Constant::getAllOnesValue(): expected behaviour or bug?
Hi Gabriel,> I was playing with the Constant::getAllOnesValue() method and found that it > doesn't handles > PointerTypes correctly.as the comment says, this is for integer types only: /// @returns the value for an integer constant of the given type that has all /// its bits set to true. /// @brief Get the all ones value static Constant *getAllOnesValue(Type* Ty); It should also mention vectors of integers (I've fixed that). Pointer types are not integer types. When receiving a "i32*" argument, it was returning with> some big integer vector, such as <12113216 x i32>. > > When you call this method passing a PointerType, the following code is executed: > > 00152 VectorType *VTy = cast<VectorType>(Ty);If you had built LLVM with assertions enabled (which you really really should when developing with LLVM) then you would have gotten an assertion failure when this cast was executed. Ciao, Duncan. PS: It would be possible to add support for pointer all-ones-values if you really need it.> 00153 return ConstantVector::getSplat(VTy->getNumElements(), > 00154 getAllOnesValue(VTy->getElementType() > > When VTy->getNumElements() is called, it returns the value of the instance > variable NumElements > present in VectorType objects, but we passed in a PointerType (SequentialType), > which doesn't have > this variable but have at the same position one variable representing the type > of the pointed thing. > > 00309 class SequentialType : public CompositeType { > 00310 Type *ContainedType; > > So getNumElements() will return some part of the value of ContainedType (an > address), which > explains that big integer vectors. > > Do you think this is an expected behaviour or a bug? > > Regards, > Gabriel > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev