[LLVMdev] Having trouble with GEP
Eli Bendersky
eliben at google.com
Wed Jan 16 08:18:00 PST 2013
> Yes:
>
> %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
> }
>
> %str = type {i8*, i64}
>
> So you're right that it does have to do with the %str type not being defined.
>
> What I'm confused about is why LLVM isn't able to generate a better
> error message than this. Perhaps this is one of those cases that
> hasn't been tested much because not many people write their IR without
> making use of LLVM's API, which would error out sooner if I tried
> this? Or is there a more fundamental reason why there's no better
> error message? Is it useful to create a bug about this?
I think it makes sense to create a bug report. Looking at the code of
LLParser::ParseGetElementPtr, the error handling appears to be very
simplistic, so I don't think there's any fundamental reason for not
doing a better job there.
Eli
More information about the llvm-dev
mailing list