Explanation

Hi All,
I am trying to check if a Value type is a int32 pointer by using

if(T == Type::getInt1PtrTy(Context, AS)) …

I am trying to understand the AS (address space).

How do I get it? Thanks.

George

Hi,

You don't need to care about address spaces to check for an int32*:

if (T->isPointerTy()) {
  const Type* intT = cast<PointerType>(T)->getElementType();
  if (intT->isIntegerTy() && intT->getPrimitiveSizeInBits() == 32)
    cout << "Yeah!" << endl;
}

Also, to create a pointer type, if you don't care about address space
at all, use the unqualified version:

const Type* ptrT = PointerType::getUnqual(intT);

cheers,
--renato

The more idiomatic way would be:
  if (const PointerType *Ptr = dyn_cast<PointerType>(T))
    if (Ptr->getElementType()->isIntegerTy(32))
      cout << "Yeah!" << endl;

John.

Nice! I was stuck with get-size-in-bits for years and never bothered
to look for an alternative, thanks! :wink:

cheers,
--renato