how to change the pointer size to 64 bits in 32bit target

Hi all developers,

I’m currently working on a RISCV target with two address mode, 32 bit and 64 bit. And all the registers are 32bits.

The first thing I dose was changing the data layout of this target. So I change the data layout string to “e-m:e-p:64:64-p1:64:32-i64:64-n32-S128” in clang/lib/Basic/Targets/RISCV.h and llvm/lib/TargetRISCV/RISCVTargteMachine.cpp.

But I found that not work as expected, following is my test code:

C language:

int func() {

return sizeof(int*);


the IR code is :

target datalayout = e-m:e-p:64:64-p1:64:32-i64:64-n32-S128

target triple = riscv32-unkown-unkown-elf

define dso_ocal i32 @func() local_unnamed_addr #0 {


ret i32 4


I see that the size of int* is 4 bytes, it is 32bits, not 64 bits as expected.

Can you tell me if I am wrong in somewhere, or the way to change the pointer size correctly.

Thank you all for your time and any help you can provide.


Clang evaluates `sizeof(x)` before it generates LLVM IR, as I think you can tell.

Look at the classes in `clang/lib/Basic/Targets/RISCV.h`. In particular, there are lots of variables in the `TargetInfo` class which give these sizes. You want to override `PointerWidth` (and also some others, in all likelihood). Look at the initializer for RISCV64TargetInfo.


Hi Sam,
   After I override TargetInfo::getPointerWidthV, `sizeof(x)` works correctly.
   Thanks a lot!