[LLVMdev] intptr_t support in llvm

ankur deshwal a.s.deshwal at gmail.com
Thu Jan 31 08:38:38 PST 2013


Hi all,

I tried compiling an opencl kernel with intptr_t datatype. However it gives
error by default using LLVM/Clang 3.2 for nvptx . To allow usage, I tried
following typedefs ( by looking at tests in llvm sources ).

typedef int intptr_t;
and
typedef __typeof( (int*) 0) intptr_t;

Both definitions compiles the code, however gives following warning.
warning: incompatible pointer to integer conversion assigning to 'int' from
'int *'; dereference with *

Is it safe to use the above typedefs ? The generated code seems correct for
x86 machines (with llvm instruction ptrtoint). Or is there better way to
make sure that the semantics of intprt_t are preserved in clang/llvm for
all archs ?

The code I tried to compile is

__kernel void intptr_t_kernel(int *a, int *b)
{
  intptr_t c = (intptr_t)a;
  b = (int*) c;
  *a += b;
}

and the code generated is

define ptx_kernel void @intptr_t_kernel(i32* %a, i32* nocapture %b)
nounwind noinline {
entry:
  %0 = load i32* %a, align 4, !tbaa !1
  %add.ptr = getelementptr inbounds i32* %a, i32 %0
  %conv = ptrtoint i32* %add.ptr to i32
  store i32 %conv, i32* %a, align 4, !tbaa !1
  ret void
}

Thanks a lot for help.

Regards,
Ankur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130131/22a344de/attachment.html>


More information about the llvm-dev mailing list