Constant::getAllOnesValue(): expected behaviour or bug?

Hi,

I was playing with the Constant::getAllOnesValue() method and found that it doesn’t handles
PointerTypes 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(Ty);
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

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.