[LLVMdev] Constant::getAllOnesValue(): expected behaviour or bug?

Duncan Sands baldrick at free.fr
Mon Jun 4 00:21:49 PDT 2012


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




More information about the llvm-dev mailing list