[LLVMdev] Having trouble with GEP

Tim Northover t.p.northover at gmail.com
Tue Jan 15 23:22:20 PST 2013


Hi Dirkjan,

I get that error when the %str type is undefined (presumably because
LLVM doesn't know its alignment requirements so can't lay out the
array$str type properly). For example, the following complete program
works correctly for me:

%str = type {i8*, i64}
%array$str = type { i64, [0 x %str] }

declare i8* @malloc(i64)

define i64 @foo(i64 %objsz) {
  %array.raw = call i8* @malloc(i64 %objsz)
  %array = bitcast i8* %array.raw to %array$str*
  %array.data = getelementptr %array$str* %array, i32 0, i32 1
  %ret = ptrtoint [0 x %str]* %array.data to i64
  ret i64 %ret
}

But it fails if the first line is commented out. Could you give a
similar complete example that has the error you're seeing?

Tim.



More information about the llvm-dev mailing list