[cfe-dev] Fwd: intptr_t support in llvm

David Tweed david.tweed at arm.com
Fri Feb 1 04:52:16 PST 2013


Leaving aside any OpenCL specific issues (you can use pointers in a more
restricted way than in general C), are you sure that the final line is doing
what you want (I think that's what the warning is about). You're adding _the
int* address held in b_ to the _int value stored at the address held in a_.
C will let you do this primarily because it's got quite weak rules about
which conversions you must do explicitly, so this will go through on a
machine where the int width is the same as an int* width.

Does the error go away if you do *a+=*b ?

 

I don't think either of your typedefs will reliably work (ie, in the
interesting cases where sizeof(int*) != sizeof(int)), I think the only way
to do it is via explicit pre-processor typedefs based on the pointer size of
the machine you're compiling on.

 

Regards,

Dave

 

From: cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu] On
Behalf Of ankur deshwal
Sent: 01 February 2013 12:02
To: cfe-dev at cs.uiuc.edu
Subject: [cfe-dev] Fwd: intptr_t support in llvm

 

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/cfe-dev/attachments/20130201/308b92d7/attachment.html>


More information about the cfe-dev mailing list