[LLVMdev] Size of structs & arrays

Fraser Cormack frasercrmck at gmail.com
Thu Feb 23 15:11:09 PST 2012



Eli Friedman-2 wrote:
> 
> 
> Try llvm::Constant::getNullValue().
> 
> 

Thanks, that's working nicely (so far).


Eli Friedman-2 wrote:
> 
> 
> Yes; [0 x i32] isn't really a variable-length array, just a
> placeholder for an array of unknown size.  You have to track the size
> yourself.
> 
> 

This is working, too, however I'm getting a segmentation fault at runtime.

  %MainClass = type { { i32, [0 x i32] } }

  %this = alloca %MainClass*
  %0 = alloca { i32, [5 x i32] }

  ... Here, I store 5 into %0[0] and a constant array into %0[1]. This runs
without error.

  %7 = load %MainClass** %this
  %8 = getelementptr inbounds %MainClass* %7, i32 0, i32 0
  %9 = getelementptr inbounds { i32, [0 x i32] }* %8, i32 0, i32 0
  %10 = getelementptr inbounds { i32, [5 x i32] }* %0, i32 0, i32 0
  %11 = load i32* %10
  store i32 %11, i32* %9
  %12 = getelementptr inbounds { i32, [0 x i32] }* %8, i32 0, i32 1
  %13 = getelementptr inbounds { i32, [5 x i32] }* %0, i32 0, i32 1
  %14 = bitcast [0 x i32]* %12 to i8*
  %15 = bitcast [5 x i32]* %13 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %14, i8* %15, i64 20, i32 4, i1
false)
  ret void

I can't see anything wrong with this bytecode (except for being verbose),
and I don't blame you if you don't want to debug it yourself, but I thought
I'd post it anyway.

If I access a value of MainClass's array after the transfer, and print it
out, then it does so successfully, then continues to segfault. So it looks
like it's copied the memory okay, but I've corrupted something in the
process..
-- 
View this message in context: http://old.nabble.com/Size-of-structs---arrays-tp33341964p33381946.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.




More information about the llvm-dev mailing list