Search code examples
c++llvmllvm-irllvm-c++-api

LLVM Check if a PointerType is a Const pointer


I Need to Know, if the a given LLVM Type of a function argument is actually a const pointer.

Is there a way to check this in LLVM?


Solution

  • What you want is probably LLVM's function and function parameter attributes. Here, for example, is check to see whether a called function's return value can ever be null:

    foo = called->hasAttribute(AttributeList::ReturnIndex, llvm::Attribute::NonNull)
    

    This checks whether a particular value is a const argument

    isa<Argument>(value) && cast<Argument>(value)->onlyReadsMemory()
    

    Well, assuming that I know what you mean by const pointer. Constness has so many shades of meaning...