Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It there an equivalent to size_t in llvm

Tags:

c

size-t

llvm

Some system libraries like malloc strlen want or return size_t as parameter.

  • What is the right choice in LLVM IR to interact with these functions?
  • Is the selection the task for the compiler?
  • Does LLVM IR have a size_t type?
like image 970
waynix Avatar asked May 30 '12 22:05

waynix


People also ask

Is Size_t a keyword?

size_t is not a keyword by necessity. Different architectures often have different sizes for integral types. For example a 64 bit machine is likely to have an unsigned long long as size_t if they didn't decide to make int a 64 bit datatype.

Why is Size_t used?

size_t is commonly used for array indexing and loop counting. Programs that use other types, such as unsigned int, for array indexing may fail on, e.g. 64-bit systems when the index exceeds UINT_MAX or if it relies on 32-bit modular arithmetic.

Can Size_t be signed?

ssize_t is not a signed size_t . It is only guaranteed to support a signed value of -1, and while it might work on Posix, it is an unsigned type on Windows.

What is Llvm used for?

LLVM is a compiler and a toolkit for building compilers, which are programs that convert instructions into a form that can be read and executed by a computer. The LLVM project is a collection of modular and reusable compiler and toolchain technologies.


1 Answers

At the LLVM level, size_t doesn't exist. It is a construct for the benefit of the developer that is typedef'd to a native type. The native types have a fixed size for the target architecture and that is how the compiler represents them in LLVM bit code. So on x86, size_t might by viewed by the front end as unsigned long, which it then writes to LLVM as i32 (since LLVM assembly doesn't have an unsigned type).

like image 83
Variable Length Coder Avatar answered Oct 01 '22 06:10

Variable Length Coder